java

位置:IT落伍者 >> java >> 浏览文章

浅析JAVA常用JDBC连接数据库的方法总结


发布日期:2020年12月03日
 
浅析JAVA常用JDBC连接数据库的方法总结

JDBC连接DB

复制代码 代码如下:
ClassforName("ComibmdbjdbcnetDBDriver");
String url="jdbc:db://dburl:port/DBname"
cn = DriverManagergetConnection( url sUsr sPwd );
ClassforName("ComibmdbjdbcnetDBDriver");
String url="jdbc:db://dburl:port/DBname"
cn = DriverManagergetConnection( url sUsr sPwd );


JDBC连接Microsoft SQLServer(microsoft)

复制代码 代码如下:
ClassforName( "commicrosoftjdbcsqlserverSQLServerDriver" );
cn = DriverManagergetConnection( "jdbc:microsoft:sqlserver://DBServerIP:;databaseName=master" sUsr sPwd );
ClassforName( "commicrosoftjdbcsqlserverSQLServerDriver" );
cn = DriverManagergetConnection( "jdbc:microsoft:sqlserver://DBServerIP:;databaseName=master" sUsr sPwd );


JDBC连接Sybase(jconnjar)

复制代码 代码如下:
ClassforName( "comsybasejdbcjdbcSybDriver" );
cn = DriverManagergetConnection( "jdbc:sybase:Tds:DBServerIP:" sUsr sPwd );
ClassforName( "comsybasejdbcjdbcSybDriver" );
cn = DriverManagergetConnection( "jdbc:sybase:Tds:DBServerIP:" sUsr sPwd );


JDBC连接MySQL(mmmysqlbinjar)

复制代码 代码如下:
ClassforName( "orggjtmmmysqlDriver" );
cn = DriverManagergetConnection( "jdbc:mysql://DBServerIP:/myDatabaseName" sUsr sPwd );
ClassforName( "orggjtmmmysqlDriver" );
cn = DriverManagergetConnection( "jdbc:mysql://DBServerIP:/myDatabaseName" sUsr sPwd );


JDBC连接PostgreSQL(pgjdbcjar)

复制代码 代码如下:
ClassforName( "orgpostgresqlDriver" );
cn = DriverManagergetConnection( "jdbc:postgresql://DBServerIP/myDatabaseName" sUsr sPwd );
ClassforName( "orgpostgresqlDriver" );
cn = DriverManagergetConnection( "jdbc:postgresql://DBServerIP/myDatabaseName" sUsr sPwd );


JDBC连接Oracle(classesjar)

复制代码 代码如下:
ClassforName( "oraclejdbcdriverOracleDriver" );
cn = DriverManagergetConnection( "jdbc:oracle:thin:@MyDbComputerNameOrIP::ORCL" sUsr sPwd );
ClassforName( "oraclejdbcdriverOracleDriver" );
cn = DriverManagergetConnection( "jdbc:oracle:thin:@MyDbComputerNameOrIP::ORCL" sUsr sPwd );


JDBC连接ODBC

复制代码 代码如下:


ClassforName( "sunjdbcodbcJdbcOdbcDriver" );
Connection cn = DriverManagergetConnection( "jdbc:odbc:" + sDsn sUsr sPwd );

上一篇:删除JAVA集合中元素的实现代码

下一篇:解析web.xml中在Servlet中获取context-param和init-param内的参数