JDBC驱动 总结
Sybase数据库
JDBC Name: jConnect
Home Page: http://www.sybase.com.cn/cn/content/SDN/
JDBC Ver: 4.5/5.5
Download: Go to the jConnect download Web page at the following URL:
http://www.sybase.com/products/middleware/jconnectforjdbc
Conn Code:
(1):
// Sybase的加载JDBC驱动程序
Class.forName("com.sybase.jdbc3.jdbc.SybDriver").newInstance();
// 与Sybase数据库建立连接
Connection dbConn = DriverManager.getConnection( "jdbc:sybase:Tds:localhost:1100", "dba", "sql");
//创建Statement
Statement st=dbConn.createStatement();
//创建一个JDBC声明
String query ="SELECT * from hzw_ov where Product_ID='?0609010021'";
ResultSet rs = st.executeQuery(query);
while(rs.next()){
String name=rs.getString(1); //获得数据库第一列
String sex=rs.getString(2);
System.out.println("姓名:"+name); //输出信息
System.out.println("性别:"+sex);
}
con.close();
(2):
try {
// Sybase的加载JDBC驱动程序
Class.forName("com.sybase.jdbc3.jdbc.SybDriver").newInstance();
System.out.println("Success loading SybDriver!");
}catch(Exception e){
System.out.println("Error loading SybDriver!");
e.printStackTrace();
}
try {
// 与Sybase数据库建立连接
Connection dbConn = DriverManager.getConnection(
"jdbc:sybase:Tds:localhost:1100/test", "dba", "sql");
System.out.println("Success Connection SybDriver!");
}catch(Exception e){
System.out.println("Error Connection SybDriver!");
e.printStackTrace();
}*/
Oracle数据库
JDBC Name: Connector/J
Home Page: http://www.oracle.com/technology/software/tech/java/
JDBC Ver: (based on Oracle)
Download: http://www.oracle.com/technology/software/tech/java/sqlj_jdbc/
Conn Code:
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con = DriverManager.getConnection("jdbc:oracle:thin:@host:port:databse","user","password");
MySQL数据库
JDBC Name: Connector/J
Home Page: http://dev.mysql.com/
JDBC Ver: 3.1
Download: http://dev.mysql.com/downloads/
Conn Code:
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://host:port/database","user","password");
JDBC使用过程
1. 加载JDBC驱动程序
Class.forName("com.mysql.jdbc.Driver";//MySQL的加载JDBC驱动程序的方法
Class.forName("org.postgresql.Driver";//PostgreSQL的加载JDBC驱动程序的方法
Class.forName("oracle.jdbc.driver.OracleDriver";//Oracle的加载JDBC驱动程序的方法
Class.forName("com.ibm.db2.jdbc.net.DB2Driver";//DB2的加载JDBC驱动程序的方法
Class.forName("com.sybase.jdbc2.jdbc.SybDriver";//Sybase的加载JDBC驱动程序的方法
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver";//SQLServer的加载JDBC驱动程序的方法
2. 建立数据库连接
与MySQL数据库建立连接的方法:Connection con=DriverManager.getConnection("jdbc:mysql://MyDbComputerNameOrIP:3306/myDBName",ID,Pwd);
与PostgreSQL数据库建立连接的方法:Connection con=DriverManager.getConnection("jdbcostgresql://MyDbComputerNameOrIP:3306/myDBName",ID,Pwd);
与Oracle数据库建立连接的方法:Connection con=DriverManager.getConnection("jdbcracle:thin:@MyDbComputerNameOrIP:1521:ORCL",ID,Pwd);
与Sybase数据库建立连接的方法:Connection con=DriverManager.getConnection("jdbc:sybase:Tds:MyDbComputerNameOrIP:2638",ID,Pwd);
与SQL Server数据库建立连接的方法:Connection con=DriverManager.getConnection("jdbc:microsoft:sqlserver://MyDbComputerNameOrIP:1433;databaseName=master",ID,Pwd);
与DB1数据库建立连接的方法:Connection con=DriverManager.getConnection("jdbc:db2://MyDbComputerN