public class MySQLInsertGenerator
extends java.lang.Object
This class provides for constructing a MySQL-specific SQL Insert statement that takes multiple value lists in one insert. This kind of insert typically runs an order of magnitude faster than individual inserts.
Modifier and Type | Field and Description |
---|---|
protected java.lang.String[] |
fieldNames
The name of the column fields, in order, for each data row.
|
protected java.lang.StringBuffer |
insertBuffer
The string buffer in which to build the insert statement.
|
protected boolean[] |
isNumeric
True if a field is a number, false otherwise.
|
protected java.lang.String |
tableName
The name of the database table into which to insert the data rows.
|
Constructor and Description |
---|
MySQLInsertGenerator(java.lang.String tableName,
java.lang.String[] fieldNames,
boolean[] isNumeric)
Create a MySQL insert generator.
|
Modifier and Type | Method and Description |
---|---|
void |
addRow(java.lang.Object[] rowData)
Add a row of data.
|
protected java.lang.String |
escapeSingleQuotes(java.lang.String value)
Escapes single quotes in a data value.
|
java.lang.String |
getInsert()
Get the insert statement.
|
protected java.lang.String tableName
protected java.lang.String[] fieldNames
protected boolean[] isNumeric
protected java.lang.StringBuffer insertBuffer
public MySQLInsertGenerator(java.lang.String tableName, java.lang.String[] fieldNames, boolean[] isNumeric)
tableName
- The database table name to receive the data.fieldNames
- The name of the column fields, in order, for
each data row.isNumeric
- True if the associated field is numeric, false
for a string.protected java.lang.String escapeSingleQuotes(java.lang.String value)
value
- The value to escape.public void addRow(java.lang.Object[] rowData)
rowData
- An Object[] array containing the data values.
Each row value must have a proper toString() method defined. The number of row values must match the number of field names passed in the contructor. If there are two many values, the extra values are ignored. If there are too few values, database null values are added.
public java.lang.String getInsert()
The string buffer used to build the insert statement is emptied. Any subsequent calls to addRow will start a new insert statement with the same table name and field names are defined in the constructor call.