JDBC里统一的使用方法
Class.for(jdbcDriverName);
Connection conn= DriverManager.getConnection(url,user,password);
这里的接口是统一的,不同的是每种数据库提供的jdbcDriver和Url不同
我们一起来看看吧
MySQL
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://host:port/database","user","password");
Oracle数据库(thin模式)
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con = DriverManager.getConnection("jdbc:oracle:thin:@host:port:databse","user","password");
Timesten数据库(thin模式)
Class.forName("com.timesten.jdbc.TimesTenDriver");
Connection con = DriverManager.getConnection("jdbc:timesten:client:dsn=dsnname")
Microsoft SQL Server
Class.forName("net.sourceforge.jtds.jdbc.Driver ");
Connection con = DriverManager.getConnection("jdbc:jtds:sqlserver://host:port/database","user","password");
or
Connection con = DriverManager.getConnection("jdbc:jtds:sybase://host:port/database","user","password");
DB2
Class.forName("com.ibm.db2.jdbc.app.DB2Driver ");
Connection conn= DriverManager.getConnection("jdbc:db2://localhost:5000/sample",user,password);
Firebird
Class.forName("org.firebirdsql.jdbc.FBDriver");
Connection con = DriverManager.getConnection("jdbc:firebirdsql://host:port/fdb_file_path","user","password");
PointBase(Server)
Class.forName("com.pointbase.jdbc.jdbcUniversalDriver");
Connection con = DriverManager.getConnection("jdbc:pointbase:server://host:port/databasename","user","password");
HSQLDB(Server)
Class.forName("org.hsqldb.jdbcDriver");
Connection con = DriverManager.getConnection("jdbc:hsqldb:hsql://localhost:port/mydb","user","password");
Derby
这个少有人听说吧,cloudscape 应该听说过吧,该项目由此衍生
Class.forName("org.apache.derby.jdbc.ClientDriver");
Connection con = DriverManager.getConnection("jdbc:derby://host:port//mydb","user","password");
Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
Connection conn = DriverManager.getConnection("jdbc:derby:mynewDB", p);
cloudscape
Class.forName("com.cloudscape.core.JDBCDriver");
Connection conn = DriverManager.getConnection("jdbc:cloudscape:<DB>");
Class.forName("com.cloudscape.rmiJdbc.RJDriver");
Connection conn = DriverManager.getConnection("jdbc:rmi://<HOST>:<PORT>/jdbc:cloudscape:<DB>", user, passoword);
Postgresql
Class.forName("org.postgresql.Driver");
Connection con=DriverManager.getConnection("jdbc:postgresql://host:port/database","user","password");
Informix
Class.forName("com.informix.jdbc.IfxDriver").newInstance();
Connection con=DriverManager.getConnection("jdbc:informix-sqli://host:port/myDB:INFORMIXSERVER=myserver","user","password");
Access
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver") ;
Connection con=DriverManager.getConnection("jdbc:odbc:Driver={MicroSoft Access Driver (*.mdb)};DBQ=mdb的文件路径","user","password");
Sybase
Class.forName("com.sybase.jdbc2.jdbc.SybDriver").newInstance();
Connection con=DriverManager.getConnection("jdbc:sybase:Tds:host:port?ServiceName=databasename","user","password");