|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object javatools.database.Database javatools.database.MySQLDatabase
public class MySQLDatabase
This class is part of the Java Tools (see http://mpii.de/yago-naga/javatools).
It is licensed under the Creative Commons Attribution License
(see http://creativecommons.org/licenses/by/3.0) by
the YAGO-NAGA team (see http://mpii.de/yago-naga).
The class MySQLDatabase implements the Database-interface for a
MySQL data base. Make sure that the file
"mysql-connector-java-version-bin.jar" from the "MySQL Connector/J"
(see the MySQL-website)
is in the classpath. When using Eclipse, add the file via Project
->Properties ->JavaBuildPath ->Libraries ->ExternalJARFile.
Example:
Database d=new MySQLDatabase("user","password","database"); d.queryColumn("SELECT foodname FROM food WHERE origin=\"Italy\"") -> [ "Pizza Romana", "Spaghetti alla Bolognese", "Saltimbocca"] Database.describe(d.query("SELECT * FROM food WHERE origin=\"Italy\"") -> foodname |origin |calories | ------------------------------ Pizza Rom|Italy |10000 | Spaghetti|Italy |8000 | Saltimboc|Italy |8000 |
Nested Class Summary | |
---|---|
static class |
MySQLDatabase.ANSIvarcharBin
a VARCHAR BINARY type, making sure we are case-sensitive in varchar fields (currently we assume case-sensitive collation is used by default, however, the method 'enforceCaseSensitivity' can replace the normal VARCHAR representation by this one, so if the database collation is not case-sensitive case-sensitive applications can use this sqltype on demand) |
static class |
MySQLDatabase.Blob
BLOB/TEXT type for MySQL |
static class |
MySQLDatabase.MysqlVarchar
VARCHAR type for MySQL |
Nested classes/interfaces inherited from class javatools.database.Database |
---|
Database.CommitTransactionSQLException, Database.ConnectionBrokenSQLException, Database.InitTransactionSQLException, Database.Inserter, Database.RollbackTransactionSQLException, Database.StartAutoCommitSQLException, Database.TransactionSQLException |
Field Summary | |
---|---|
static MySQLDatabase.ANSIvarcharBin |
ansivarcharbin
|
static MySQLDatabase.Blob |
blob
|
static MySQLDatabase.MysqlVarchar |
mysqlvarchar
|
Fields inherited from class javatools.database.Database |
---|
java2SQL, MINCOLUMNWIDTH, SCREENWIDTH, type2SQL |
Constructor Summary | |
---|---|
MySQLDatabase()
|
|
MySQLDatabase(java.lang.String user,
java.lang.String password,
java.lang.String database,
java.lang.String host,
java.lang.String port)
Constructs a new MySQLDatabase from a user and a password, all other arguments may be null |
Method Summary | |
---|---|
java.lang.String |
autoincrementColumn()
Produces an SQL fragment representing column properties for an autoincrementing integer column s.t. |
java.lang.String |
cast(java.lang.String value,
java.lang.String type)
Produces an SQL fragment casting the given value to the given type * |
void |
connect()
connects to the database specified |
void |
enforceCaseSensitivity(boolean enable)
allows to make sure VARCHAR column field based queries are case-sensitive even when the underlying table has a case-insensitive collation |
java.lang.String |
getSQLStmntIFNULL(java.lang.String a,
java.lang.String b)
returns the database system specific expression for ifnull functionality i.e. |
boolean |
jarAvailable()
TRUE if the required JAR is there |
void |
lockTableReadAccess(java.util.Map<java.lang.String,java.lang.String> tablesAndAliases)
Locks a table in read mode, i.e. |
void |
lockTableWriteAccess(java.util.Map<java.lang.String,java.lang.String> tablesAndAliases)
Locks a table in write mode, i.e. |
static void |
main(java.lang.String[] args)
|
void |
releaseLocksAndEndTransaction()
releases all locks the connection holds, commits the current transaction and ends it switches back to autocommit mode |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static MySQLDatabase.MysqlVarchar mysqlvarchar
public static MySQLDatabase.Blob blob
public static MySQLDatabase.ANSIvarcharBin ansivarcharbin
Constructor Detail |
---|
public MySQLDatabase(java.lang.String user, java.lang.String password, java.lang.String database, java.lang.String host, java.lang.String port) throws java.lang.InstantiationException, java.lang.IllegalAccessException, java.lang.ClassNotFoundException, java.sql.SQLException
java.lang.InstantiationException
java.lang.IllegalAccessException
java.lang.ClassNotFoundException
java.sql.SQLException
public MySQLDatabase()
Method Detail |
---|
public void enforceCaseSensitivity(boolean enable)
public void connect() throws java.sql.SQLException
connect
in class Database
java.sql.SQLException
public boolean jarAvailable()
Database
jarAvailable
in class Database
public void lockTableWriteAccess(java.util.Map<java.lang.String,java.lang.String> tablesAndAliases) throws java.sql.SQLException
lockTableWriteAccess
in class Database
java.sql.SQLException
public void lockTableReadAccess(java.util.Map<java.lang.String,java.lang.String> tablesAndAliases) throws java.sql.SQLException
lockTableReadAccess
in class Database
java.sql.SQLException
public void releaseLocksAndEndTransaction() throws java.sql.SQLException
releaseLocksAndEndTransaction
in class Database
java.sql.SQLException
public java.lang.String getSQLStmntIFNULL(java.lang.String a, java.lang.String b)
getSQLStmntIFNULL
in class Database
public java.lang.String cast(java.lang.String value, java.lang.String type)
cast
in class Database
public java.lang.String autoincrementColumn()
autoincrementColumn
in class Database
public static void main(java.lang.String[] args) throws java.lang.Exception
java.lang.Exception
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |