java连接数据库

1 Java 连接 Oralce
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance(); 
String url="jdbc:oracle:thin:@localhost:1521:orcl";   
Connection conn= DriverManager.getConnection(url,user,password); 
2 Java 连接 MySQL
Class.forName("org.gjt.mm.mysql.Driver ").newInstance();
String URL = "jdbc:mysql://localhost/testDB";
Connection conn= DriverManager.getConnection(url,user,password);
3 Java 连接SQLServer
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver ").newInstance();
String URL =” jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=testDB"; 
Connection conn= DriverManager.getConnection(url,user,password);
4 Java 连接DB2
Class.forName(“com.ibm.db2.jdbc.app.DB2Driver ").newInstance();
String URL =”jdbc:db2://localhost:5000/sample"; 
Connection conn= DriverManager.getConnection(url,user,password);
5 Java 连接 Infomix
Class.forName("com.informix.jdbc.IfxDriver ").newInstance();
String URL =jdbc:informix-sqli://123.45.67.89:1533/testDB:INFORMIXSERVER=myserver
Connection conn= DriverManager.getConnection(url,user,password);
6 Java 连接 SyBase
Class.forName("com.sybase.jdbc.SybDriver").newInstance();
Properties sysProps = System.getProperties(); 
SysProps.put("user","userid"); 
SysProps.put("password","user_password"); 
Connection conn= DriverManager.getConnection(url, SysProps);
7 Java连接 PostgreSQL
Class.forName("org.postgresql.Driver").newInstance(); 
String url ="jdbc:postgresql://localhost/ltmp" 
Connection conn= DriverManager.getConnection(url,user,password);

你可能感兴趣的:(java,mysql,jdbc,db2,Sybase)