浅析JAVA常用JDBC连接数据库的方法总结
程序员文章站
2023-12-15 19:09:04
一、jdbc连接db2复制代码 代码如下:class.forname("com.ibm.db2.jdbc.net.db2driver"); stri...
一、jdbc连接db2
class.forname("com.ibm.db2.jdbc.net.db2driver");
string url="jdbc:db2://dburl:port/dbname"
cn = drivermanager.getconnection( url, susr, spwd );
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 );
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 );
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 );
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 );
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 );
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 );
复制代码 代码如下:
class.forname("com.ibm.db2.jdbc.net.db2driver");
string url="jdbc:db2://dburl:port/dbname"
cn = drivermanager.getconnection( url, susr, spwd );
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 );
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 );
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 );
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 );
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 );
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 );