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(); } }