|
<p >1、Oracle8/8i/9i数据库(thin模式) <p >Class.forName("oracle.jdbc.driver.OracleDriver").newInstance(); <p >String url="jdbc racle:thin localhost:1521 rcl"; //orcl为数据库的SID <p >String user="test"; <p >String password="test"; <p >Connection conn= DriverManager.getConnection(url,user,password); <p >2、DB2数据库 <p >Class.forName("com.ibm.db2.jdbc.app.DB2Driver ").newInstance(); <p >String url="jdbc:db2://localhost:5000/sample"; //sample为你的数据库名 <p >String user="admin"; <p >String password=""; <p >Connection conn= DriverManager.getConnection(url,user,password); <p >3、SQL Server7.0/2000数据库 <p >Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance(); <p >String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=mydb"; <p >//mydb为数据库 <p >String user="sa"; <p >String password=""; <p >Connection conn= DriverManager.getConnection(url,user,password); <p >4、Sybase数据库 <p >Class.forName("com.sybase.jdbc.SybDriver").newInstance(); <p >String url =" jdbc:sybase:Tds:localhost:5007/myDB";//myDB为你的数据库名 <p > roperties sysProps = System.getProperties(); <p >SysProps.put("user","userid"); <p >SysProps.put("password","user_password"); <p >Connection conn= DriverManager.getConnection(url, SysProps); <p >5、Informix数据库 <p >Class.forName("com.informix.jdbc.IfxDriver").newInstance(); <p >String url = "jdbc:informix-sqli://123.45.67.89:1533/myDB:INFORMIXSERVER=myserver; <p >user=testuser;password=testpassword"; //myDB为数据库名 <p >Connection conn= DriverManager.getConnection(url); <p >6、MySQL数据库 <p >Class.forName("org.gjt.mm.mysql.Driver").newInstance(); <p >//或者Class.forName("com.mysql.jdbc.Driver"); <p >String url ="jdbc:mysql://localhost/myDB? <p >user=soft&password=soft1234&useUnicode=true&characterEncoding=8859_1" <p >//myDB为数据库名 <p >Connection conn= DriverManager.getConnection(url); <p >7、PostgreSQL数据库 <p >Class.forName("org.postgresql.Driver").newInstance(); <p >String url ="jdbc:postgresql://localhost/myDB" //myDB为数据库名 <p >String user="myuser"; <p >String password="mypassword"; <p >Connection conn= DriverManager.getConnection(url,user,password); <p >8、access数据库直连用ODBC的 <p >Class.forName("sun.jdbc.odbc.JdbcOdbcDriver") ; <p >String url="jdbc dbc river={MicroSoft Access Driver <p >(*.mdb)};DBQ="+application.getRealPath("/Data/ReportDemo.mdb"); <p >Connection conn = DriverManager.getConnection(url,"",""); <p >Statement stmtNew=conn.createStatement() ;<p ><p >(责任编辑:董建伟) <p align="center"></p></p> |
|