public abstract class SQL
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
java.sql.Connection |
connection |
java.lang.String |
database |
java.lang.String |
driver |
java.lang.String |
previousQuery |
java.sql.ResultSet |
result |
java.lang.String |
server |
java.sql.Statement |
statement |
java.lang.String |
type |
java.lang.String |
url |
java.lang.String |
user |
Constructor and Description |
---|
SQL()
Do not use this contructor.
|
SQL(processing.core.PApplet _pa,
java.lang.String _db)
You should not directly use the SQL.class instead use the classes for your database type.
|
SQL(processing.core.PApplet _pa,
java.lang.String _serv,
java.lang.String _db,
java.lang.String _u,
java.lang.String _p)
You should not directly use the SQL.class instead use the classes for your database type.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Close the database connection
|
boolean |
connect()
Open the database connection with the parameters given in the contructor.
|
void |
dispose()
Callback function for PApplet.registerDispose()
|
java.lang.String |
escape(java.lang.Object o)
Generate an escaped String for a given Object
|
void |
execute(java.lang.String _sql)
Execute a SQL command on the open database connection.
|
void |
execute(java.lang.String _sql,
java.lang.Object... args)
Execute a SQL command on the open database connection.
|
java.math.BigDecimal |
getBigDecimal(int _column)
Read a java.math.BigDecimal value from the specified field.
|
java.math.BigDecimal |
getBigDecimal(java.lang.String _field)
Read a java.math.BigDecimal value from the specified field.
|
byte[] |
getBlob(int _column)
Read a value from the specified field to have it returned as an byte[]
|
byte[] |
getBlob(java.lang.String _field)
Read a value from the specified field to have it returned as an byte[]
|
boolean |
getBoolean(int _column)
Read a boolean value from the specified field.
|
boolean |
getBoolean(java.lang.String _field)
Read a boolean value from the specified field.
|
java.lang.String[] |
getColumnNames()
Returns an array with the column names of the last request.
|
java.sql.Connection |
getConnection()
Get connection.
|
java.sql.Date |
getDate(int _column)
Read a java.sql.Date value from the specified field.
|
java.sql.Date |
getDate(java.lang.String _field)
Read a java.sql.Date value from the specified field.
|
boolean |
getDebug()
Get current debugging setting
|
double |
getDouble(int _column)
Read a double value from the specified field.
|
double |
getDouble(java.lang.String _field)
Read a double value from the specified field.
|
java.lang.String |
getDriverVersion()
Return the version of the currently active JDBC driver
|
float |
getFloat(int _column)
Read a float value from the specified field.
|
float |
getFloat(java.lang.String _field)
Read a float value from the specified field.
|
int |
getInt(int _column)
Read an integer value from the specified field.
|
int |
getInt(java.lang.String _field)
Read an integer value from the specified field.
|
long |
getLong(int _column)
Read a long value from the specified field.
|
long |
getLong(java.lang.String _field)
Read a long value from the specified field.
|
NameMapper |
getNameMapper()
Get the current NameMapper
|
java.lang.Object |
getObject(int _column)
Read a value from the specified field to have it returned as an object.
|
java.lang.Object |
getObject(java.lang.String _field)
Read a value from the specified field to have it returned as an object.
|
java.lang.String |
getString(int _column)
Read a String value from the specified field.
|
java.lang.String |
getString(java.lang.String _field)
Read a String value from the specified field.
|
abstract java.lang.String[] |
getTableNames()
Get names of available tables in active database,
needs to be implemented per db adapter.
|
java.sql.Time |
getTime(int _column)
Read a java.sql.Time value from the specified field.
|
java.sql.Time |
getTime(java.lang.String _field)
Read a java.sql.Time value from the specified field.
|
java.sql.Timestamp |
getTimestamp(int _column)
Read a java.sql.Timestamp value from the specified field.
|
java.sql.Timestamp |
getTimestamp(java.lang.String _field)
Read a java.sql.Timestamp value from the specified field.
|
void |
insertUpdateInDatabase(java.lang.String tableName,
java.lang.String[] columnNames,
java.lang.Object[] values)
Insert or update a bunch of values in the database.
|
java.lang.String |
nameToGetter(java.lang.String name)
Convert a field name to a getter name: fieldName -> getFieldName().
|
java.lang.String |
nameToSetter(java.lang.String name)
Convert a field name to a setter name: fieldName -> setFieldName().
|
boolean |
next()
Check if more results (rows) are available.
|
void |
query(java.lang.String _sql)
Issue a query on the open database connection
|
void |
query(java.lang.String _sql,
java.lang.Object... args)
Issue a query on the open database connection.
|
void |
registerTableNameForClass(java.lang.String name,
java.lang.Object classOrObject)
Set a table name for a class.
|
void |
saveToDatabase(java.lang.Object object)
Take an object, try to find table name from object name (or look it up),
get fields and getters from object and pass that on to
insertUpdateIntoDatabase(table, columns, values).
|
void |
saveToDatabase(java.lang.String tableName,
java.lang.Object object)
Takes a table name and an object and tries to construct a set of
columns names from fields and getters found in the object.
|
void |
setDebug(boolean yesNo)
Turn some debugging on/off.
|
void |
setFromRow(java.lang.Object object)
Highly experimental ...
tries to map column names to public fields or setter methods in the given object. |
void |
setNameMapper(NameMapper mapper)
Set the current NameMapper
|
public java.lang.String server
public java.lang.String database
public java.lang.String url
public java.lang.String user
public java.lang.String driver
public java.lang.String type
public java.sql.Connection connection
public java.lang.String previousQuery
public java.sql.Statement statement
public java.sql.ResultSet result
public SQL()
public SQL(processing.core.PApplet _pa, java.lang.String _db)
public SQL(processing.core.PApplet _pa, java.lang.String _serv, java.lang.String _db, java.lang.String _u, java.lang.String _p)
public void setDebug(boolean yesNo)
yesNo
- Turn it on or offpublic boolean getDebug()
yesNo
- Turn it on or offpublic boolean connect()
public java.lang.String getDriverVersion()
public void execute(java.lang.String _sql)
_sql
- The SQL command to executepublic void execute(java.lang.String _sql, java.lang.Object... args)
_sql
- SQL command as pattern for String.format()args
- Zero or more objects to be passed to String.format()String.format(java.lang.String,java.lang.Object...)
public void query(java.lang.String _sql)
_sql
- SQL command to execute for the querypublic void query(java.lang.String _sql, java.lang.Object... args)
_sql
- SQL command as pattern for String.format()args
- Zero or more objects to be passed to String.format()String.format(java.lang.String,java.lang.Object...)
public boolean next()
public abstract java.lang.String[] getTableNames()
public java.lang.String[] getColumnNames()
public java.sql.Connection getConnection()
public int getInt(java.lang.String _field)
_field
- The name of the fieldpublic int getInt(int _column)
_column
- The column index of the field to readpublic long getLong(java.lang.String _field)
_field
- The name of the fieldpublic long getLong(int _column)
_column
- The column index of the fieldpublic float getFloat(java.lang.String _field)
_field
- The name of the fieldpublic float getFloat(int _column)
_column
- The index of the column of the fieldpublic double getDouble(java.lang.String _field)
_field
- The name of the fieldpublic double getDouble(int _column)
_column
- The column index of the fieldpublic java.math.BigDecimal getBigDecimal(java.lang.String _field)
_field
- The name of the fieldpublic java.math.BigDecimal getBigDecimal(int _column)
_column
- The column index of the fieldpublic boolean getBoolean(java.lang.String _field)
_field
- The name of the fieldpublic boolean getBoolean(int _column)
_column
- The column index of the fieldpublic java.lang.String getString(java.lang.String _field)
_field
- The name of the fieldpublic java.lang.String getString(int _column)
_column
- The column index of the fieldpublic java.sql.Date getDate(java.lang.String _field)
_field
- The name of the fieldpublic java.sql.Date getDate(int _column)
_column
- The column index of the fieldpublic java.sql.Time getTime(java.lang.String _field)
_field
- The name of the fieldpublic java.sql.Time getTime(int _column)
_column
- The column index of the fieldpublic java.sql.Timestamp getTimestamp(java.lang.String _field)
_field
- The name of the fieldpublic java.sql.Timestamp getTimestamp(int _column)
_column
- The column index of the fieldpublic byte[] getBlob(java.lang.String _field)
_field
- The name of the fieldpublic byte[] getBlob(int _column)
_column
- The column index of the fieldpublic java.lang.Object getObject(java.lang.String _field)
_field
- The name of the fieldpublic java.lang.Object getObject(int _column)
_column
- The column index of the fieldpublic void close()
public void dispose()
processing.core.PApplet.registerDispose(java.lang.Object)
public java.lang.String escape(java.lang.Object o)
object
- the Object to escapepublic void setNameMapper(NameMapper mapper)
mapper
- the name mapperNameMapper
public NameMapper getNameMapper()
NameMapper
public void setFromRow(java.lang.Object object)
Highly experimental ...
tries to map column names to public fields or setter methods
in the given object.
Use like so:
db.query("SELECT name, id, sometime FROM table"); while ( db.next() ) { SomeObject obj = new SomeObject(); db.setFromRow(obj); // obj.name is now same as db.getString("name"), etc. }
SomeObject might look like:
class SomeObject { public String name; public int id; Date sometime; }
object
- The object to populate from the currently selected rowpublic java.lang.String nameToSetter(java.lang.String name)
public java.lang.String nameToGetter(java.lang.String name)
public void registerTableNameForClass(java.lang.String name, java.lang.Object classOrObject)
public void saveToDatabase(java.lang.Object object)
object
- Object The object to save to dbinsertUpdateInDatabase(java.lang.String, java.lang.String[], java.lang.Object[])
public void saveToDatabase(java.lang.String tableName, java.lang.Object object)
tableName
- String The name of the tableobject
- Object The object to look atinsertUpdateInDatabase(java.lang.String, java.lang.String[], java.lang.Object[])
public void insertUpdateInDatabase(java.lang.String tableName, java.lang.String[] columnNames, java.lang.Object[] values)
tableName
- String The name of the tablecolumnNames
- String[] The names of the columns to fill or updatevalues
- Object[] The values to instert or updateProcessing library BezierSQLib (formerly SQLibrary) by Florian Jenett. (c) 2005 - 2023