What the java.sql
Package Contains html
java.sql
package contains API for the following:
DriverManager
facility 經過驅動管理器工具與數據庫創建鏈接 DriverManager
class 類 -- makes a connection with a driver 與驅動程序創建鏈接 SQLPermission
class 類-- provides permission when code running within a Security Manager, such as an applet, attempts to set up a logging stream through the DriverManager
在安全管理器(如applet)中運行的代碼試圖經過驅動程序管理器設置日誌流時,提供權限 Driver
interface 接口 -- provides the API for registering and connecting drivers based on JDBC technology ("JDBC drivers"); generally used only by the DriverManager
class提供基於JDBC技術的驅動程序註冊和鏈接API(「JDBC驅動程序」);一般只被DriverManager類使用 DriverPropertyInfo
class 類 -- provides properties for a JDBC driver; not used by the general user 爲JDBC驅動程序提供屬性;通常用戶不使用 Statement
-- used to send basic SQL statements 執行對象,用於發送基本的SQL語句 PreparedStatement
-- used to send prepared statements or basic SQL statements (derived from Statement
) 用於發送準備好的語句或基本SQL語句(從Statement派生) CallableStatement
-- used to call database stored procedures (derived from PreparedStatement
) 用於調用數據庫存儲過程(從PreparedStatement 派生) Connection
interface 接口 -- provides methods for creating statements and managing connections and their properties 提供用於建立語句和管理鏈接及其屬性的方法 Savepoint
-- provides savepoints in a transaction 在事務中提供Savepoint保存點 ResultSet
interface 接口 Array
interface 接口-- mapping for SQL ARRAY SQL ARRAY映射
Blob
interface 接口-- mapping for SQL BLOB SQL BLOB映射
Clob
interface接口 -- mapping for SQL CLOB SQL CLOB 映射
Date
class 類-- mapping for SQL DATE
NClob
interface 接口 -- mapping for SQL NCLOB
Ref
interface 接口-- mapping for SQL REF
RowId
interface 接口-- mapping for SQL ROWID
Struct
interface 接口-- mapping for SQL STRUCT
SQLXML
interface 接口-- mapping for SQL XML
Time
class 類-- mapping for SQL TIME
Timestamp
class 類-- mapping for SQL TIMESTAMP
Types
class 類-- provides constants for SQL types 爲SQL類型提供常量 SQLData
interface -- specifies the mapping of a UDT to an instance of this class 指定UDT到該類實例的映射 SQLInput
interface -- provides methods for reading UDT attributes from a stream 提供從流中讀取UDT屬性的方法 SQLOutput
interface -- provides methods for writing UDT attributes back to a stream 提供將UDT屬性寫回流的方法 DatabaseMetaData
interface -- provides information about the database 提供有關數據庫的信息 ResultSetMetaData
interface -- provides information about the columns of a ResultSet
object 提供有關ResultSet對象的列的信息 ParameterMetaData
interface -- provides information about the parameters to PreparedStatement
commands 爲PreparedStatement命令提供有關參數的信息 SQLException
-- thrown by most methods when there is a problem accessing data and by some methods for other reasons 當訪問數據存在問題時大多數方法都會拋出這個異常,還有一些方法是其餘緣由拋出這個異常。 SQLWarning
-- thrown to indicate a warning 拋出以表示警告 DataTruncation
-- thrown to indicate that data may have been truncated 拋出以指示數據可能已被截斷 BatchUpdateException
-- thrown to indicate that not all commands in a batch update executed successfully 拋出以指示批處理更新中並不是全部命令都已成功執行 package jdbc.jdbc; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement; /** * 第一個JDBC * @author noteless */ public class FirstJDBC { public static void main(String[] args) throws Exception { //一、註冊驅動 Class.forName("com.mysql.jdbc.Driver"); //數據庫鏈接所需參數 String user = "root"; String password = "123456"; String url = "jdbc:mysql://localhost:3306/sampledb?useUnicode=true&characterEncoding=utf-8"; //二、獲取鏈接對象 Connection conn = DriverManager.getConnection(url, user, password); //設置sql語句 String sql = "select * from student"; //三、得到sql語句執行對象 Statement stmt = conn.createStatement(); //四、執行sql並保存結果集 ResultSet rs = stmt.executeQuery(sql); //五、處理結果集 while (rs.next()) { System.out.print("id:" + rs.getInt(1)); System.out.print(",姓名:" + rs.getString(2)); System.out.print(",年齡:" + rs.getInt(3)); System.out.println(",性別:" + rs.getString(4)); } //六、資源關閉 rs.close(); stmt.close(); conn.close(); } }