Add data to fields, in preparation for insertion into a database.
When adding data in a many-to-many relation, if setAutoManyToMany is set to false, a null row should be inserted into the relating table so the datamanager will link the keys correctly between related tables. For example, dm.addData("many_to_many", null);
Before adding data the first time, you must build the schema of any tables you will use, as well as add foreign keys if you are not using a database engine that natively supports them (such as InnoDB for MySQL).
The SqlDataManager will attempt to convert a value that is given to the correct format for the database. For example, if the database requires an int for a column named age, dm.addData("table", "age", "32") will convert the String "32" to an int before adding it to the database. See the table below the examples for other types of java objects and how they map to SQL types.
The table and columnName parameters are not case sensitive. The same is true for the key values in the data map.
Returns void.
Version | Description |
---|---|
5.0 | Available for professional and enterprise editions. |
Since the DataManager is designed with screen-scraper in mind all inputs support using the String type in addition to their corresponding Java object type, but the String needs to be parseable into the corresponding data type. For example if there is a column that is defined as an Integer in the database then the String needs to be parseable by Integer.parseInt(String value). Here is a mapping of the sql types (based on java.sql.Types) to Java objects:
SQL Type | Java Object | |
---|---|---|
java.sql.Types.CHAR | String | |
java.sql.Types.VARCHAR | String | |
java.sql.Types.LONGVARCHAR | String | |
java.sql.Types.LONGNVARCHAR | String | |
java.sql.Types.NUMERIC | BigDecimal | |
java.sql.Types.DECIMAL | BigDecimal | |
java.sql.Types.TINYINT | Integer | |
java.sql.Types.SMALLINT | Integer | |
java.sql.Types.INTEGER | Integer | |
java.sql.Types.BIGINT | Long | |
java.sql.Types.REAL | Float | |
java.sql.Types.FLOAT | Double | |
java.sql.Types.DOUBLE | Double | |
java.sql.Types.BIT | Boolean | |
java.sql.Types.BINARY | ByteArray | |
java.sql.Types.VARBINARY | ByteArray | |
java.sql.Types.LONGVARBINARY | ByteArray | |
java.sql.Types.DATE | SQLDate or Long | |
java.sql.Types.TIME | SQLTime or Long | |
java.sql.Types.TIMESTAMP | SQLTime or Long | |
java.sql.Types.ARRAY | Object | |
java.sql.Types.BLOB | ByteArray | |
java.sql.Types.CLOB | Object | |
java.sql.Types.JAVA_OBJECT | Object | |
java.sql.Types.OTHER | Object |