java.lang.Object
org.seppiko.commons.utils.jdbc.SQLExecutor
- All Implemented Interfaces:
Closeable,AutoCloseable
SQL executor
- Author:
- Leonard Woo
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Close ConnectionintExecuteINSERTUPDATEDELETEor other statement.intExecuteINSERTUPDATEDELETEor other statement.longExecuteINSERTUPDATEDELETEor other statement.longexecuteWithGeneratedKey(String sql, Object... params) ExecuteINSERTUPDATEDELETEor other statement.Query ExecuteSELECTstatementQuery ExecuteSELECTstatement
-
Constructor Details
-
SQLExecutor
Initialize SQL executor- Parameters:
conn- the connection.- Throws:
NullPointerException- connection is null
-
-
Method Details
-
query
Query ExecuteSELECTstatement- Parameters:
sql- SQL Statement.- Returns:
- a
ResultSetobject that contains the data produced by the given query; nevernull - Throws:
SQLException- if a database access error occurs.IllegalArgumentException- SQL is empty or null.
-
query
Query ExecuteSELECTstatement- Parameters:
sql- SQL Statement.params- parameters.- Returns:
- a
ResultSetobject that contains the data produced by the given query; nevernull - Throws:
SQLException- if a database access error occurs.IllegalArgumentException- SQL is empty or null.
-
execute
ExecuteINSERTUPDATEDELETEor other statement.- Parameters:
sql- SQL Statement.- Returns:
- SQL execute row count.
- Throws:
SQLException- if a database access error occurs.IllegalArgumentException- SQL is empty or null.
-
execute
ExecuteINSERTUPDATEDELETEor other statement.- Parameters:
sql- SQL Statement.params- parameters.- Returns:
- SQL execute row count.
- Throws:
SQLException- if a database access error occurs.IllegalArgumentException- SQL is empty or null.
-
executeWithGeneratedKey
ExecuteINSERTUPDATEDELETEor other statement. And return generated key.- Parameters:
sql- SQL Statement.- Returns:
- auto-generated key, -1 is Fail, and 0 is not get key.
- Throws:
SQLException- if a database access error occurs.IllegalArgumentException- SQL is empty or null.
-
executeWithGeneratedKey
public long executeWithGeneratedKey(String sql, Object... params) throws SQLException, IllegalArgumentException ExecuteINSERTUPDATEDELETEor other statement. And return generated key.- Parameters:
sql- SQL Statement.params- parameters.- Returns:
- auto-generated key, -1 is Fail, and 0 is not get key.
- Throws:
SQLException- if a database access error occurs.IllegalArgumentException- SQL is empty or null.
-
close
Close Connection- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException- if a database access error occurs.
-