JDBC,which you can think of as a JAVA version of ODBC ,and is itself a growing standerd. JavaSoft has also provided a bridge driver that translates JDBC to ODBC.
To use the database follows these steps:
1.Load the JDBC drivers.
Class.forName(JDBCDriver); //for JDBC-ODBC bridge is sun.jdbc.odbc.JdbcOdbcDriver
//and for MySQL Connector/J is com.mysql.jdbc.Driver
//you must import java.sql.*
2.Connect to a data source.
Connection con = DriverManager.getConnection(
URL ,
username ,
password );
3.Send SQL statements .
stmt = con.createStatement();
stmt.execute(SQLString);
To use the database follows these steps:
1.Load the JDBC drivers.
Class.forName(JDBCDriver); //for JDBC-ODBC bridge is
//and for MySQL Connector/J is
//you must import java.sql.*
2.Connect to a data source.
Connection con = DriverManager.getConnection(
3.Send SQL statements .
stmt = con.createStatement();
stmt.execute(SQLString);
本文介绍了如何使用JDBC连接数据库,包括加载驱动、建立连接及发送SQL语句等步骤,并提供了针对不同数据库的具体示例。
1万+

被折叠的 条评论
为什么被折叠?



