笔记:常用JDBC API整理(持续更新)

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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值