jdbc的driver怎么写

1.eclipse 连接mysql jdbc怎么写常用JDBC连接数据库方法总结如下:
一、JDBC连接DB2
Class.forName("Com.ibm.db2.jdbc.net.DB2Driver");
String url="jdbc:db2://dburl:port/DBname"
cn = DriverManager.getConnection( url, sUsr, sPwd );
二、JDBC连接Microsoft SQLServer(microsoft)
Class.forName( "com.microsoft.jdbc.sqlserver.SQLServerDriver" );
cn = DriverManager.getConnection( "jdbc:microsoft:sqlserver://DBServerIP:1433;databaseName=master", sUsr, sPwd );
三、JDBC连接Sybase(jconn2.jar)
Class.forName( "com.sybase.jdbc2.jdbc.SybDriver" );
cn = DriverManager.getConnection( "jdbc:sybase:Tds:DBServerIP:2638", sUsr, sPwd );
四、JDBC连接MySQL(mm.mysql-3.0.2-bin.jar)
Class.forName( "org.gjt.mm.mysql.Driver" );
cn = DriverManager.getConnection( "jdbc:mysql://DBServerIP:3306/myDatabaseName", sUsr, sPwd );
五、JDBC连接PostgreSQL(pgjdbc2.jar)
Class.forName( "org.postgresql.Driver" );
cn = DriverManager.getConnection( "jdbc:postgresql://DBServerIP/myDatabaseName", sUsr, sPwd );
六、JDBC连接Oracle(classes12.jar)
Class.forName( "oracle.jdbc.driver.OracleDriver" );
cn = DriverManager.getConnection( "jdbc:oracle:thin:@MyDbComputerNameOrIP:1521:ORCL", sUsr, sPwd );
七、JDBC连接ODBC
Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver" );
Connection cn = DriverManager.getConnection( "jdbc:odbc:" + sDsn, sUsr, sPwd );
转载,仅供参考 。
2.JDBC连接类的代码怎么写`/*
* Created on 2004-6-3
*
* 连接数据库的相关操作
*
*/
package connect;
/**
* @author Ambrosini
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
import java.sql.*;
import java.util.*;
public class DataConnect {
String driverName = "sun.jdbc.odbc.JdbcOdbcDriver";
String databaseURL = "jdbc:odbc:Test";
String usr = "Test";
String psword = "Test";
Vector vector;
Connection connection=null;
Statement statement=null;
ResultSet resultSet=null;
ResultSetMetaData rsMetaData=http://www.xuexi88.com/zhishi/null;
//连接数据库
public DataConnect(){
vector =new Vector();
try{
Class.forName(driverName);
【jdbc的driver怎么写】}catch(ClassNotFoundException e){System.err.println(e.getMessage());}
}
//返回结果集
public ResultSet getResulet(String sql){
String sql2000 = sql ;
try{
connection = DriverManager.getConnection(databaseURL,usr,psword);
statement = connection.createStatement();
resultSet = statement.executeQuery(sql2000);
rsMetaData = http://www.xuexi88.com/zhishi/resultSet.getMetaData();
}catch(SQLException ee){System.err.println(ee.getMessage());}
return resultSet;
}
//关闭连接
public void shutDown() {
try{
connection.close();
}catch(SQLException ex){System.err.println(ex.getMessage());}
}
//更改数据库操作
public void executeUpdate(String sql) {
try {
connection = DriverManager.getConnection(databaseURL,usr,psword);
statement = connection.createStatement();
statement.executeUpdate(sql);
}
catch(SQLException ee) {
System.err.println(ee.getMessage());
}
}
}
3.jdbc oracle加载驱动类语句怎么写Oracle(thin)数据库连接:
1.Class.forName("oracle.jdbc.driver.OracleDriver");
2.DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:[DataBase Name]","scott","tiger");
本机专用:
con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","scott","tiger");
Oracle(OCI driver)数据库连接:
1.Class.forName("oracle.jdbc.driver.OracleDriver");
2.DriverManager.getConnection("jdbc:oracle:oci8:@localhost:1521:[DataBase Name]","scott","tiger");