JDBC连接数据库

时间:2021-02-09 19:05:13

/**Oracle*/
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
String url="jdbc:oracle:thin:@localhost:1521:orcl;
String user="system";
String pwd="manager12345";
java.sql.Connection conn=DriverManager.getConnection(url,user,pwd);

/**Sybase**/
Class.forName("com.sybase.jdbc.SybDriver").newInstance();
String url="jdbc:sybase:Tds:localhost:5007/erp";
Properties sysProps=System.getProperties();
Sysprops.put("user","sa");
Sysprops.put("password","");
java.sql.Connection conn=DriverManager.getConnection(url,SysProps);

/**DB2**/
Class.forName("com.ibm.db2.jdbc.app.DB2Driver").newInstance();
String url="jdbc:db2://localhost:5000/sample;
String user="admin";
String pwd="";
java.sql.Connection conn=DriverManager.getConnection(url,user,pwd);

/**Informix**/
Class.forName("com.informix.jdbc.InxDriver").newInstance();
String url="jdbc:informix-sqli://localhost:1533/test:INFORMIXSERVER=infserver;
String user="sa";
String pwd="pwd";
java.sql.Connection conn=DriverManager.getConnection(url,user,pwd);

/**sql server**/
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=pubs;
String user="sa";
String pwd="";
java.sql.Connection conn=DriverManager.getConnection(url,user,pwd);

/**PostgreSQL**/
Class.forName("org.postgresql.Driver").newInstance();
String url="jdbc:postgresql://localhost/netshop;
String user="root";
String pwd="";
java.sql.Connection conn=DriverManager.getConnection(url,user,pwd);