Read Me
****************************************************************************
*********************** JAVA MYSQL DATABASE UTILITY **********************
****************************************************************************
*
* Copyright 2005 The Regents of the University of Michigan
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
****************************************************************************
Contact: James "Augie" Hill - augman85@gmail.com
****************************************************************************
The API is best used by creating a static org.tranche.mysql.MySQLDatabase object, then performing your SQL queries on that object.
Let's say we have created our object like so: static MySQLDatabase myDB = new MySQLDatabase(Vars.HOST, Vars.DB, Vars.USER, Vars.USERPASS);
Then a standard query will look like this:
ResultSet rs = null;
try {
rs = myDB.executeQuery(SQL.QUERY);
while (rs.next()) {
// do something with a row
}
} catch (Exception e) {
// do something
} finally {
MySQLUtil.safeClose(rs);
}
A query that performs an update will look like this:
if (!MySQLUtil.executeUpdate(SQL.QUERY, myDB)) {
// failed, do something
}
A query that performs an insert will look like this:
int pk = MySQLUtil.executeInsert(SQL.QUERY, myDB);
if (pk == -1) {
// failed, do something
}