public class DbHelper
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private java.sql.Connection |
dBconnection
The d bconnection.
|
private java.sql.ResultSet |
resultSet
The result set.
|
private java.sql.Statement |
statement
The statement.
|
Constructor and Description |
---|
DbHelper() |
Modifier and Type | Method and Description |
---|---|
void |
closeStatement()
close the current statement if it is open.
|
void |
connect(java.lang.String host,
java.lang.String database,
java.lang.String driver,
java.lang.String user,
java.lang.String password)
connect to database using specified parameters.
|
void |
disconnect()
Disconnect from database and clean up.
|
java.sql.Connection |
getConnection()
Gets the connection.
|
static void |
main(java.lang.String[] args)
The main method.
|
java.sql.ResultSet |
runPrecompiledInsert(java.lang.String schemaName,
java.lang.String tableName,
java.util.HashMap<java.lang.String,java.lang.String> valueMap)
Build a precompiled inset based on the data types in the table.
|
java.sql.ResultSet |
runRawSQL(java.lang.String stmt)
Run an unchecked sql command.
|
void |
setAutoCommit(boolean val) |
boolean |
tableExists(java.lang.String tableName)
See if the named table exists in the database we're using.
|
private java.sql.Connection dBconnection
private java.sql.Statement statement
private java.sql.ResultSet resultSet
public void connect(java.lang.String host, java.lang.String database, java.lang.String driver, java.lang.String user, java.lang.String password) throws java.lang.Exception
host
- the host name (i.e. "jdbc:mysql://localhost:3306/")database
- the mySQL database (i.e. "mySqlDatabase")driver
- the driver (i.e. "com.mysql.jdbc.Driver")user
- the user (i.e. "myUserName")password
- the password (i.e. "myCleverPassword")java.lang.Exception
- the exceptionpublic void setAutoCommit(boolean val)
public void disconnect()
public java.sql.ResultSet runRawSQL(java.lang.String stmt) throws java.lang.Exception
stmt
- the SQL query ("select * from table_foo")java.lang.Exception
- the exceptionpublic java.sql.ResultSet runPrecompiledInsert(java.lang.String schemaName, java.lang.String tableName, java.util.HashMap<java.lang.String,java.lang.String> valueMap) throws java.lang.Exception
schemaName
- the schema nametableName
- the table namevalueMap
- the value HashMapjava.lang.Exception
public java.sql.Connection getConnection()
public void closeStatement() throws java.sql.SQLException
java.sql.SQLException
public boolean tableExists(java.lang.String tableName)
tableName
- the table namepublic static void main(java.lang.String[] args)
args
- the arguments