SQL server 0.7、2000
driver="com.microsoft.jdbc.sqlserver.SQLServerDviver"
url="jdbc:microsoft:sqlserver://localhost:1433;DatebaseName=数据库名称"
url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=Blog;user=sa;password=123"
利用jtds第三方驱动来连接sqlserver,该驱动可解决微软JDBC驱动的兼容性问题,数据顺序查询问题。
driver ="net.sourceforge.jtds.jdbc.Driver";
url="jdbc:jtds:sqlserver://localhost:1433;DatabaseName=stml_demo";
SQL server 2005、2008
driver="com.microsoft.sqlserver.jdbc.SQLServerDriver";
url="jdbc:sqlserver://localhost:1433;DatabaseName=数据库名称"
url="jdbc:sqlserver://localhost:1433;DatabaseName=Blog;user=sa;password=123"
MySQL 5.0
driver="com.mysql.jdbc.Driver" 或 “org.gjt.mm.mysql.Driver”(不推荐使用)
url="jdbc:mysql://localhost:3306/数据库名称"
url="jdbc:mysql://localhost:3306/数据库名称?user=root&password=123";
Oracle8/8i/9i数据库(thin模式) Oracle10g
driver = "oracle.jdbc.driver.OracleDriver";
url = "jdbc:oracle:thin:@ localhost:1521:数据库实例";
其他数据库(转载自:http://blog.sina.com.cn/s/blog_5e6e077e0100don6.html)
DB2数据库
Class.forName("com.ibm.db2.jdbc.app.DB2Driver ").newInstance();
String url="jdbc:db2://localhost:5000/sample"; //sample为你的数据库名
String user="userNm";
String password="***";
Connection conn= DriverManager.getConnection(url,user,password);
Sybase数据库
Class.forName("com.sybase.jdbc.SybDriver").newInstance();
String url =" jdbc:sybase:Tds:localhost:5007/myDB";//myDB为你的数据库名
Properties sysProps = System.getProperties();
SysProps.put("user","userNm");
SysProps.put("password","***");
Connection conn= DriverManager.getConnection(url, SysProps);
Informix数据库
Class.forName("com.informix.jdbc.IfxDriver").newInstance();
String url =
"jdbc:informix-sqli://123.45.67.89:1533/myDB:INFORMIXSERVER=myserver;
user=userNm;password=***"; //myDB为数据库名
Connection conn= DriverManager.getConnection(url);
PostgreSQL数据库
Class.forName("org.postgresql.Driver").newInstance();
String url ="jdbc:postgresql://localhost/myDB" //myDB为数据库名
String user="myuser";
String password="mypassword";
Connection conn= DriverManager.getConnection(url,user,password);
access数据库直连用ODBC的
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver") ;
String url="jdbc:odbc:Driver={MicroSoft Access Driver (*.mdb)};DBQ="+application.getRealPath("/Data/ReportDemo.mdb");
Connection conn = DriverManager.getConnection(url,"","");
Statement stmtNew=conn.createStatement() ;
各类数据库驱动的下载链接接:
jTDS:http://sourceforge.net/project/showfiles.php?group_id=33291
MySQL:http://www.mysql.com/downloads/api-jdbc-stable.html
Oracle:http://otn.oracle.com/software/tech/java/sqlj_jdbc/content.html
Postgresql:http://jdbc.postgresql.org/download.html