2种连接数据库和读取sql文件添加数据库和表
import java.io.*;
import java.sql.*;
public class DBConn {
private String ADDRESS ;
private int PORT ;
private String DBNAME ;
private String USERNAME ;
private String PASSWORD ;
private Connection conn ;
private PreparedStatement pstmt ;
private Statement stmt ;
private ResultSet rs ;
/***
* 连接MYSQL数据库
* @return
*/
public Connection getMySqlConn(){
try{
ADDRESS = "127.0.0.1";
PORT = 3306;
DBNAME = "test";
USERNAME = "root";
PASSWORD = "123456";
if(conn==null){
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql://"+ADDRESS+":"+PORT+"?user="+USERNAME+"&password="+PASSWORD+"&useUnicode=true&characterEncoding=utf8");
}
}catch(Exception e){
e.printStackTrace();
}
return conn;
}
/***
* 连接MSSQL数据库
* @return
*/
public Connection getMSSqlConn(){
try{
ADDRESS = "127.0.0.1";
PORT = 1433;
DBNAME = "mytest";
USERNAME = "sa";
PASSWORD = "";
if(conn==null){
Class.forName("net.sourceforge.jtds.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:jtds:sqlserver://"+ADDRESS+":"+PORT,USERNAME,PASSWORD);
}
}catch(Exception e){
e.printStackTrace();
}
return conn;
}
/**
* 关闭数据库连接
* @return
*/
public void closeConn(){
try{
相关文档:
create table aaa
(
id int primary key ,
name varchar(30) not null
)
create table bbb
(
id int primary key ,
name varchar(30) not null
)
--交
select * from aaa
where exists
(
select * from bbb where aaa.id=bbb.id and aaa.name = bbb.name
)
--差
select *
from bbb
where not exists
(
......
string s = " 80,81,83,82";
string[] s1 = s.Split(',');
int[] p = new int[s1.Count()];
for (int i = 0; i < s1.Count( ......
--行列互转
/******************************************************************************************************************************************************
以学生成绩为例子,比较形象易懂
整理人:中国风(Roy)
日期:2008.06.06
***************************************************************** ......
alter procedure qry_page
@sqlstr nvarchar(4000), --查询字符串
@page int, --第N页
@pagesize int &n ......