📄 dbcommon.java
字号:
package com.gd.jdbc;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;
import javax.sql.rowset.CachedRowSet;
public interface DbCommon {
/**
* 该方法用来设定下面的方法是否使用PreparedStatement
*/
public void setPstmt();
/**
* 用来获取单笔数据结果集,该方法默认使用Statement,如果要使用PreparedStatement,则要首先调用setPstmt()方法,
* 并且使用PreparedStatement时,sql语句必须是完整的,而不是带有?的,即中途不能设定参数
* @param sql
* @return ResultSet
* @throws SQLException
*/
public ResultSet getResultSet(String sql) throws SQLException;
/**
* 用来获取单笔数据结果集,该方法默认使用Statement,如果要使用PreparedStatement,则要首先调用setPstmt()方法,
* 并且使用PreparedStatement时,sql语句必须是完整的,而不是带有?的,即中途不能设定参数
* @param sql
* @return CachedRowSet
* @throws SQLException
*/
public CachedRowSet getCachedRowSet(String sql) throws SQLException;
/**
* 用来获取多笔数据结果集,该方法默认使用Statement,如果要使用PreparedStatement,则要首先调用setPstmt()方法,
* 并且使用PreparedStatement时,sql语句必须是完整的,而不是带有?的,即中途不能设定参数
* @param sql
* @param limit,用来限制查询笔数,<=0则代表不限制
* @return ResultSet
* @throws SQLException
*/
public ResultSet getAllResultSet(String sql, int limit) throws SQLException;
/**
* 用来获取多笔数据结果集,该方法默认使用Statement,如果要使用PreparedStatement,则要首先调用setPstmt()方法,
* 并且使用PreparedStatement时,sql语句必须是完整的,而不是带有?的,即中途不能设定参数
* @param sql
* @param limit,用来限制查询笔数,<=0则代表不限制
* @return CachedRowSet
* @throws SQLException
*/
public CachedRowSet getAllCachedRowSet(String sql, int limit) throws SQLException;
/**
* 用来获取单笔数据结果集,该方法默认使用Statement,如果要使用PreparedStatement,则要首先调用setPstmt()方法,
* 并且使用PreparedStatement时,sql语句必须是完整的,而不是带有?的,即中途不能设定参数
* @param sql
* @return Map
* @throws SQLException
*/
public Map queryMap(String sql) throws SQLException;
/**
* 用来获取单笔数据结果集,希望返回的是对象,可以转换为Javabean,该方法默认使用Statement,如果要使用PreparedStatement,则要首先调用setPstmt()方法,
* 并且使用PreparedStatement时,sql语句必须是完整的,而不是带有?的,即中途不能设定参数
* @param sql
* @return Object
* @throws SQLException
*/
public Object queryObj(String sql) throws SQLException;
/**
* 用来获取多笔数据结果集,该方法默认使用Statement,如果要使用PreparedStatement,则要首先调用setPstmt()方法,
* 并且使用PreparedStatement时,sql语句必须是完整的,而不是带有?的,即中途不能设定参数
* @param sql
* @param limit,用来限制查询笔数,<=0则代表不限制
* @return Map[]
* @throws SQLException
*/
public Map[] queryAllMap(String sql, int limit) throws SQLException;
/**
* 用来获取多笔数据结果集,希望返回的是对象,可以转换为Javabean,该方法默认使用Statement,如果要使用PreparedStatement,则要首先调用setPstmt()方法,
* 并且使用PreparedStatement时,sql语句必须是完整的,而不是带有?的,即中途不能设定参数
* @param sql
* @param limit,用来限制查询笔数,<=0则代表不限制
* @return List
* @throws SQLException
*/
public List queryAllObj(String sql, int limit) throws SQLException;
/**
* 该方法用来更新数据库的资料,该方法默认使用Statement,如果要使用PreparedStatement,则要首先调用setPstmt()方法,
* 并且使用PreparedStatement时,sql语句必须是完整的,而不是带有?的,即中途不能设定参数
*
* @param sql
* @return int 返回值为0时,表示更新失败
* @exception SQLException
*/
public int executeUpdate(String sql) throws SQLException;
/**
* 用来获取单笔数据结果集,该方法使用PreparedStatement,且不用先调用setPstmt()方法,
* 并且使用PreparedStatement时,sql语句可以是带有?的,即中途可以设定参数,但使用该方法必须先调用PreparedStatement()方法
* @return ResultSet
* @throws SQLException
*/
public ResultSet getResultSet() throws SQLException;
/**
* 用来获取单笔数据结果集,该方法使用PreparedStatement,且不用先调用setPstmt()方法,
* 并且使用PreparedStatement时,sql语句可以是带有?的,即中途可以设定参数,但使用该方法必须先调用PreparedStatement()方法
* @return CachedRowSet
* @throws SQLException
*/
public CachedRowSet getCachedRowSet() throws SQLException;
/**
* 用来获取多笔数据结果集,该方法使用PreparedStatement,且不用先调用setPstmt()方法,
* 并且使用PreparedStatement时,sql语句可以是带有?的,即中途可以设定参数,但使用该方法必须先调用PreparedStatement()方法
* @return ResultSet
* @throws SQLException
*/
public ResultSet getAllResultSet() throws SQLException;
/**
* 用来获取多笔数据结果集,该方法使用PreparedStatement,且不用先调用setPstmt()方法,
* 并且使用PreparedStatement时,sql语句可以是带有?的,即中途可以设定参数,但使用该方法必须先调用PreparedStatement()方法
* @return CachedRowSet
* @throws SQLException
*/
public CachedRowSet getAllCachedRowSet() throws SQLException;
/**
* 用来获取单笔数据结果集,该方法使用PreparedStatement,且不用先调用setPstmt()方法,
* 并且使用PreparedStatement时,sql语句可以是带有?的,即中途可以设定参数,但使用该方法必须先调用PreparedStatement()方法
* @return Map
* @throws SQLException
*/
public Map queryMap() throws SQLException;
/**
* 用来获取单笔数据结果集,希望返回的是对象,可以转换为Javabean,该方法使用PreparedStatement,且不用先调用setPstmt()方法,
* 并且使用PreparedStatement时,sql语句可以是带有?的,即中途可以设定参数,但使用该方法必须先调用PreparedStatement()方法
* @return Object
* @throws SQLException
*/
public Object queryObj() throws SQLException;
/**
* 用来获取多笔数据结果集,该方法使用PreparedStatement,且不用先调用setPstmt()方法,
* 并且使用PreparedStatement时,sql语句可以是带有?的,即中途可以设定参数,但使用该方法必须先调用PreparedStatement()方法
* @return Map[]
* @throws SQLException
*/
public Map[] queryAllMap() throws SQLException;
/**
* 用来获取多笔数据结果集,希望返回的是对象,可以转换为Javabean,该方法使用PreparedStatement,且不用先调用setPstmt()方法,
* 并且使用PreparedStatement时,sql语句可以是带有?的,即中途可以设定参数,但使用该方法必须先调用PreparedStatement()方法
* @return List
* @throws SQLException
*/
public List queryAllObj() throws SQLException;
/**
* 该方法用来更新数据库的资料,该方法使用PreparedStatement,且不用先调用setPstmt()方法,
* 并且使用PreparedStatement时,sql语句可以是带有?的,即中途可以设定参数,但使用该方法必须先调用PreparedStatement()方法
* @return int 返回值为0时,表示更新失败
* @exception SQLException
*/
public int executeUpdate() throws SQLException;
/**
* 用来通过PreparedStatement设定多笔数据结果集
* @param sql
* @param limit,用来限制查询笔数,<=0则代表不限制
* @return void
* @throws SQLException
*/
public void PreparedStatement(String sql, int limit) throws SQLException;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -