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
(
......
配置源程序
附加数据库SQL Server 2005
(1)将TM\01\App_Data文件夹中的db_SIS.mdf和db_SIS_log.ldf文件拷贝到SQL Server 2005安装路径下的MSSQL.1\MSSQL\Data目录下。
(2)选择开始/程序/Microsoft SQL Server 2005/SQL Server Management Studio项,进入到“连接到服务器”页面,如图1.1所示。
图1.1&nbs ......
SQL分页
万能分页
.net代码
select top 每页显示的记录数 * from topic where id not in
(select top (当前的页数-1)×每页显示的记录数 id from topic order by id desc)  ......
原文出处:http://www.dingos.cn/index.php?topic=1874.0
定义和用法
CONVERT() 函数是把日期转换为新数据类型的通用函数。
CONVERT() 函数可以用不同的格式显示日期/时间数据
语法
CONVERT(data_type(length),data_to_be_converted,style)
data_type(length) 规定目标数据类型(带有可选的长度)。data_to_be_conv ......