Class DBConnection
- java.lang.Object
-
- com.github.collinalpert.java2db.database.DBConnection
-
- All Implemented Interfaces:
java.lang.AutoCloseable
public class DBConnection extends java.lang.Object implements java.lang.AutoCloseable- Author:
- Collin Alpert
- See Also:
- GitHub
-
-
Constructor Summary
Constructors Constructor Description DBConnection()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Closes the connection to the database.java.sql.ResultSetexecute(java.lang.String query)Executes an SELECT SQL statement on the database without Java parameters.java.sql.ResultSetexecute(java.lang.String query, java.lang.Object... params)Executes an SELECT SQL statement on the database with Java parameters.booleanisOpen()Determines if a connection to the database still exists or not.booleanisValid()Checks if the connection is valid/successful.booleanupdate(java.lang.String query)This command is used for any queries that are supposed to update the database, such as UPDATE, DELETE, TRUNCATE etc.booleanupdate(java.lang.String query, java.lang.Object... params)This command is used for any queries that are supposed to update the database, such as UPDATE, DELETE, TRUNCATE etc.
-
-
-
Method Detail
-
isValid
public boolean isValid()
Checks if the connection is valid/successful.- Returns:
- True if connection was successful, false if not.
-
execute
public java.sql.ResultSet execute(java.lang.String query)
Executes an SELECT SQL statement on the database without Java parameters.- Parameters:
query- The query to be executed.- Returns:
- The
ResultSetcontaining the result from the SELECT query.
-
execute
public java.sql.ResultSet execute(java.lang.String query, java.lang.Object... params)Executes an SELECT SQL statement on the database with Java parameters.- Parameters:
query- The query to be executed.params- The Java parameters to be inserted into the query.- Returns:
- The
ResultSetcontaining the result from the SELECT query.
-
update
public boolean update(java.lang.String query)
This command is used for any queries that are supposed to update the database, such as UPDATE, DELETE, TRUNCATE etc.- Parameters:
query- The query to be executed.- Returns:
Trueif the update was successful,falseif not.
-
update
public boolean update(java.lang.String query, java.lang.Object... params)This command is used for any queries that are supposed to update the database, such as UPDATE, DELETE, TRUNCATE etc.- Parameters:
query- The query to be executed.params- The Java parameters to be inserted into the query.- Returns:
Trueif the update was successful,falseif not.
-
isOpen
public boolean isOpen()
Determines if a connection to the database still exists or not.- Returns:
Trueif a connection exists,falseif not. This method will returnfalseif an exception occurs.
-
close
public void close()
Closes the connection to the database.- Specified by:
closein interfacejava.lang.AutoCloseable
-
-