A Mysql8 JDBC Handler for java
Simply load the jar file as a library. (Found in releases section).
To use, call the DatabaseHandler class.
- Create a new instance of it, as it will hold the data to create the connection to the database.
- Provide a
Map<String, String>or a properties file name to one of the following functions.
DatabaseHandler dbh = new DatabaseHandler();
// Calling the properties file.
dbh.readProperties("properties.prop");
// Calling the map for data.
dbh.setDetails();- Open a connection before updating or reading from the database.
dbh.doConnect();- Close the database connection after you are done.
dbh.doClose(); readProperties( );
doStatement( );
setDetails( );
doConnect( );
doUpdate( );
doQuery( );
doClose( );
Returns a map of all the variables from the propertie file.
Usage : dbh.readProperties( propertyFileNameString );
Used to load all the config data from a properties file. Read below for what data is required in both the map and the properties file.
Returns either an int or ResultSet depending on chosen method.
Usage : doStatement( sqlQueryString ); - Returns ResultSet.
Usage : doStatement( sqlQueryString, "update" ); - Returns int.
Used to query or update the database.
Returns hashmap of what the internal variables have been set to.
Usage : dbh.setDetails( Map<String, String> );
Used to set the connection information.
Returns true or false based on if the connection was successful or not.
Usage : dbh.doConnect();
Used to open a connection to the database on which you can run your update or query commands.
There are multiple overloaded methods regarding this, all return an int of 1 or 0. 1 means it ran sucessfully.
Usage : dbh.doUpdate( sqlQueryString );
Usage : dbh.doUpdate( sqlQueryString, List<Object> );
The second overloaded method replaces all the ? in your sqlQueryString with the data in the relative position of List<Object>
There are multiple overloaded methods regarding this, all return a ResultSet.
Usage : dbh.doQuery( sqlQueryString );
Usage : dbh.doQuery( sqlQueryString, List<Object> );
The second overloaded method replaces all the ? in your sqlQueryString with the data in the relative position of List<Object>
Returns true or false based on if the operation was successful
Usage : dbh.doClose();
Used to close the connection to the database.
url- Url is simply the http:// url of the database, along with the/database. (There is no need for thejdbcinformation at the start. EG.http://localhost:3306/mydbusername- String of the username to connect to the database.password- String of the password to connect to the database.