1、mysql
驱动包:mysql-connector-java-3.0.17-ga-bin.jar
连接方式:
String strDriver="com.mysql.jdbc.Driver";
String strUrl="jdbc:mysql://localhost:3306/mytest?useUnicode=true;characterEncoding=utf-8";
String strUser="root";
String strPwd="xxxx";
try{
Class.forName(strDriver);
Connection conn=DriverManager.getConnection(strUrl,strUser,strPwd);
System.out.print("ok!");
}catch(SQLException e){
e.printStackTrace();
}
return conn;
2、oracle
驱动包:classes12.jar、ojdbc14.jar
连接方式:
驱动:oracle.jdbc.driver.OracleDriver
jdbc:oracle:thin:@host:1521:数据库名(orcl)","username", "passwd");
jdbc:oracle:thin:@host:1521:SID
host是数据库安装的机器IP地址,本机则可用localhost
1521是端口号,固定
SID 是创建数据库时让你输入的标记该数据库的ID
查看SID :select * from v$instance;
3、SQL2000
驱动包:msbase.jar、mssqlserver.jar、msutil.jar
连接方式:
String driverName = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
String dbURL = "jdbc:microsoft:sqlserver://localhost:1433; DatabaseName=数据库名";
String username="sa";
String pswd="xx"
try{
Class.forName(driverName );
Connection conn=DriverManager.getConnection(dbURL ,username,pswd);
System.out.print("ok!");
}catch(SQLException e){
e.printStackTrace();
}
4、SQL2005
驱动包:sqljdbc.jar
连接方式:
String driverName = "com.microsoft.sqlserver.jdbc.SQLServerDriver"; //加载JDBC驱动
String dbURL = "jdbc:sqlserver://localhost:1433;DatabaseName=sample"; //连接服务器和数据库sample
String userName = "sa"; //默认用户名
String userPwd = "xx";
try{
Class.forName(driverName );
Connection conn=DriverManager.getConnection(dbURL ,userName ,userPwd );
System.out.print("ok!");
}catch(SQLException e){
e.printStackTrace();
}
5、SQL最新全能版本
驱动包:sqljdbc4.jar
连接方式:
号称可以连接SQL2000、2005、2008的JDBC,支持4.0的驱动。反正目前连着2000没有问题,希望以后换2005和2008都会没有问题
String driverName ="com.microsoft.sqlserver.jdbc.SQLServerDriver";
String url = "jdbc:sqlserver://localhost:1433;DatabaseName=数据库名";
String user = "sa";
String password = "xx";
try{
Class.forName(driverName );
Connection conn = DriverManager.getConnection(url, user, password);
System.out.print("ok!");
}catch(SQLException e){
e.printStackTrace();
}
驱动包:mysql-connector-java-3.0.17-ga-bin.jar
连接方式:
String strDriver="com.mysql.jdbc.Driver";
String strUrl="jdbc:mysql://localhost:3306/mytest?useUnicode=true;characterEncoding=utf-8";
String strUser="root";
String strPwd="xxxx";
try{
Class.forName(strDriver);
Connection conn=DriverManager.getConnection(strUrl,strUser,strPwd);
System.out.print("ok!");
}catch(SQLException e){
e.printStackTrace();
}
return conn;
2、oracle
驱动包:classes12.jar、ojdbc14.jar
连接方式:
驱动:oracle.jdbc.driver.OracleDriver
jdbc:oracle:thin:@host:1521:数据库名(orcl)","username", "passwd");
jdbc:oracle:thin:@host:1521:SID
host是数据库安装的机器IP地址,本机则可用localhost
1521是端口号,固定
SID 是创建数据库时让你输入的标记该数据库的ID
查看SID :select * from v$instance;
3、SQL2000
驱动包:msbase.jar、mssqlserver.jar、msutil.jar
连接方式:
String driverName = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
String dbURL = "jdbc:microsoft:sqlserver://localhost:1433; DatabaseName=数据库名";
String username="sa";
String pswd="xx"
try{
Class.forName(driverName );
Connection conn=DriverManager.getConnection(dbURL ,username,pswd);
System.out.print("ok!");
}catch(SQLException e){
e.printStackTrace();
}
4、SQL2005
驱动包:sqljdbc.jar
连接方式:
String driverName = "com.microsoft.sqlserver.jdbc.SQLServerDriver"; //加载JDBC驱动
String dbURL = "jdbc:sqlserver://localhost:1433;DatabaseName=sample"; //连接服务器和数据库sample
String userName = "sa"; //默认用户名
String userPwd = "xx";
try{
Class.forName(driverName );
Connection conn=DriverManager.getConnection(dbURL ,userName ,userPwd );
System.out.print("ok!");
}catch(SQLException e){
e.printStackTrace();
}
5、SQL最新全能版本
驱动包:sqljdbc4.jar
连接方式:
号称可以连接SQL2000、2005、2008的JDBC,支持4.0的驱动。反正目前连着2000没有问题,希望以后换2005和2008都会没有问题
String driverName ="com.microsoft.sqlserver.jdbc.SQLServerDriver";
String url = "jdbc:sqlserver://localhost:1433;DatabaseName=数据库名";
String user = "sa";
String password = "xx";
try{
Class.forName(driverName );
Connection conn = DriverManager.getConnection(url, user, password);
System.out.print("ok!");
}catch(SQLException e){
e.printStackTrace();
}