JDBC API
常用的接口、类与方法
interface Connection
A connection (session) with a specific database.
Connection是与特定数据库的会话
void close()
//Releases this Connection object's database and JDBC resources immediately instead of waiting for them to be automatically released.
//释放Connection占用的JDBC资源
Statement createStatement() throws SQLException
//Creates a Statement object for sending SQL statements to the database.
//创建用于发送sql语句的statement对象
interface Statement
Statement用于执行静态sql语句并返回其生成的结果的对象(ResultSet或是其他基本数据类型)
ResultSet executeQuery(String sql) throws SQLException
//Executes the given SQL statement, which returns a single ResultSet object.
//执行给定的sql语句,并返回ResultSet对象
Connection getConnection()
//Retrieves the Connection object that produced this Statement object.
//检索生成Statement的Connection并返回
void close()
//Releases this Statement object's database and JDBC resources immediately instead of waiting for this to happen when it is automatically closed.
//释放Statement所占用的JDBC资源
interface ResultSet
ResultSet是表示数据库结果集的数据表,通常由执行查询数据库的语句生成
method get…
get…方法 以Java中的类型检索ResultSet对象当前行中指定列的值
所有get…方法都有参数为列名与列号的两个重载,此处以String为例:
String getString(int columnIndex) throws SQLException
//Retrieves the value of the designated column in the current row of this ResultSet object as a String in the Java programming language.
//以String类型返回当前行指定列的值,存在参数为String column lable的重载
以此类推还有Int,Double,Date,Object等等
其他
boolean next()
//Moves the cursor forward one row from its current position.
//将光标移至下一行,如未至表尾,返回true
boolean previous()
//Moves the cursor to the previous row in this ResultSet object.
//将光标移至上一行,如未至表头,返回true
Class DriverManager
static Connection getConnection(String url, String user, String password)
//Attempts to establish a connection to the given database URL.
//尝试与给定数据库url进行连接,并返回Connection