下面介绍最常用的数据库驱动程序的加载方法
Oracle
Class.forName("oracle.jdbc.driver.OracleDirver"); String url= "jdbc:oracle:thin:@localhost:1521:oracle"; String user = "test"; String password = "test"; Connection conn = DriverManger.getConnection(url,user,password);
SqlServer2000
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver"); String url = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=mydb"; String url = "sa"; String password = "sa"; Connection conn = DriverManger.getConnection(url,user,password);
SqlServer2005
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); String url ="jdbc:sqlserver://localhost;database=AdventureWorks"; String user = "sa"; String password = ""; Connection conn = DriverManager.getConnection(url,user,password);
Access
String url = "jdbc:odbc:driver={Microsoft AccessDriver(*.mdb)};DBQ=databaseName.mdb"; Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection conn = DriverManager(url);
DB2
Class.forName("com.ibm.db2.jdbc.app.DB2Driver"); String url ="jdbc:db2://localhost:5000/sample";//sample数据库or的名称 String url = "admin"; String password = ""; Connection comm = Connection.getConnection(url,user,password);
Mysql
Class.forName("com.mysql.jdbc.Driver/message"); String user="root"; String password = "root"; Connection conn = DriverManger.getConnection(url,user,password);
Sybase
Class.forName("com.sybasebDriver"); String url = "jdbc:sybase:Tds:localhost:5007/myDb";//myDb为数据库 Properties sysProps = System.getProperties(); SysProps.put("user","userid"); SysProps.put("password","user_pass"); Connection conn = DriverManager.getConnection(url,SysProps);