JDBC操作各种数据库经验技巧集萃

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

你可能感兴趣的:(mysql,jdbc,db2,Sybase,Informix)