常用数据库的JDBC连接

//oracle  
  Class.forName("oracle.jdbc.driver.OracleDriver");        
  String   url="jdbc:oracle:thin:@localhost:1521:orcl";   //orcl为你的数据库的SID    
  String   user="scott";    
  String   password="tiger";    
  Connection   conn=   DriverManager.getConnection(url,user,password);        
  Statement   stmt=conn.createStatement();    
       
  //sql   server  
  Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");        
  String   url="jdbc:microsoft:   sqlserver://localhost:1433;DatabaseName=pubs";   //pubs为你的数据库的    
  String   user="sa";    
  String   password="";    
  Connection   conn=   DriverManager.getConnection(url,user,password);        
  Statement   stmt=conn.createStatement();    
       
  //DB2  
  Class.forName("com.ibm.db2.jdbc.app.DB2Driver   ");        
  String   url="jdbc:   db2://localhost:5000/sample";   //sample为你的数据库名    
  String   user="admin";    
  String   password="";    
  Connection   conn=   DriverManager.getConnection(url,user,password);        
  Statement   stmt=conn.createStatement();  
   
  //mysql  
  Class.forName("org.gjt.mm.mysql.Driver").newInstance();        
  String   url   ="jdbc:   mysql://localhost/softforum?user=soft&password=soft1234&useUnicode=true&characterEncoding=8859_1"   //testDB为你的数据库名    
  Connection   conn=   DriverManager.getConnection(url);        
  Statement   stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);     

阅读更多
换一批

常用数据库JDBC连接

10-24

1、Oracle8/8i/9i数据库(thin模式)rnClass.forName("oracle.jdbc.driver.OracleDriver").newInstance();rnString url="jdbc:oracle:thin:@localhost:1521:orcl"; //orcl为数据库的SIDrnString user="test";rnString password="test";rnConnection conn= DriverManager.getConnection(url,user,password);rnrn2、DB2数据库rnClass.forName("com.ibm.db2.jdbc.app.DB2Driver ").newInstance();rnString url="jdbc:db2://localhost:5000/sample"; //sample为你的数据库名rnString user="admin";rnString password="";rnConnection conn= DriverManager.getConnection(url,user,password);rnrn3、Sql Server7.0/2000数据库rnClass.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();rnString url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=mydb";rn//mydb为数据库rnString user="sa";rnString password="";rnConnection conn= DriverManager.getConnection(url,user,password);rnrn4、Sybase数据库rnClass.forName("com.sybase.jdbc.SybDriver").newInstance();rnString url =" jdbc:sybase:Tds:localhost:5007/myDB";//myDB为你的数据库名rnProperties sysProps = System.getProperties();rnSysProps.put("user","userid");rnSysProps.put("password","user_password");rnConnection conn= DriverManager.getConnection(url, SysProps);rnrn5、Informix数据库rnClass.forName("com.informix.jdbc.IfxDriver").newInstance();rnString url =rn"jdbc:informix-sqli://123.45.67.89:1533/myDB:INFORMIXSERVER=myserver;rnuser=testuser;password=testpassword"; //myDB为数据库名rnConnection conn= DriverManager.getConnection(url);rnrn6、MySQL数据库rnClass.forName("org.gjt.mm.mysql.Driver").newInstance();rnString url ="jdbc:mysql://localhost/myDB?user=soft&password=soft1234&useUnicode=true&characterEncoding=8859_1"rn//myDB为数据库名rnConnection conn= DriverManager.getConnection(url); rnrn

没有更多推荐了,返回首页