jdbc连接步骤及连接大全

    jdbc连接步骤(以oracle为例):
1,加载驱动
class.forname("oracle.jdbc.driver.oracledriver");
 
2, 建立连接
connection cn = drivermanager.getconnection("jdbc:oracle:thin:@10.49.0.6:1521:orcl", "tvcms_dev", "tvcms_dev");
 
3, 建立 statement
statement st = cn.createstatement();
 
4, 执行 sql,获得结果集
resultset rs = st.excutequery(sql);
 
5, 处理结果集
while(rs.next()){
 rs.getobject("字段名")
}
 
6, 关闭资源
finally{
 rs = null;
 st = null;
 cn = null;
}
 
 
-------------连接大全-----------
一、db2 
class.forname("com.ibm.db2.jdbc.net.db2driver"); 
string url="jdbc:db2://dburl:port/dbname" 
cn = drivermanager.getconnection( url, susr, spwd );
 
二、microsoft sqlserver(microsoft) 
class.forname( "com.microsoft.jdbc.sqlserver.sqlserverdriver" ); 
cn = drivermanager.getconnection( "jdbc:microsoft:sqlserver://dbserverip:1433;databasename=master", susr, spwd ); 
 
三、sybase(jconn2.jar)
class.forname( "com.sybase.jdbc2.jdbc.sybdriver" ); 
cn = drivermanager.getconnection( "jdbc:sybase:tds:dbserverip:2638", susr, spwd ); 
 
四、mysql(mm.mysql-3.0.2-bin.jar)
class.forname( "org.gjt.mm.mysql.driver" ); 
cn = drivermanager.getconnection( "jdbc:mysql://dbserverip:3306/mydatabasename", susr, spwd ); 
 
五、postgresql(pgjdbc2.jar)
class.forname( "org.postgresql.driver" ); 
cn = drivermanager.getconnection( "jdbc:postgresql://dbserverip/mydatabasename", susr, spwd ); 
 
六、oracle(classes12.jar) 
class.forname( "oracle.jdbc.driver.oracledriver" ); 
cn = drivermanager.getconnection( "jdbc:oracle:thin:@mydbcomputernameorip:1521:orcl", susr, spwd ); 
 

你可能感兴趣的:(java,工作)