Thanks for taking the time Ulric,
I'm using sqlitejdbc-v054 from http://files.zentus.com/sqlitejdbc/, I
notice they are up to v056, so I'll give that a go.
The stack trace
<error>
ERROR 53:13 [DB.prepareStatement() 697]: Error in sql: INSERT INTO
delay_forms (t2_access_wp_action_required, t2_access_key,
t2_access_vegetation, t2_access_streetlight_blocked, t2_access_other,
t4_safety_wp_action_required, t4_safety_hv_line_too_close,
t4_safety_network_unsafe, t4_safety_danger_tag_reference, t4_safety_other,
t4_safety_additional_information, t7_cant_find_job_wp_action_required,
t7_cant_find_job_site_visit_check, t7_cant_find_job_dfis_check,
t7_cant_find_job_street_directory_check, t7_cant_find_job_dome_check,
t7_cant_find_job_pole_check, t7_cant_find_job_streetlights_check,
t7_cant_find_job_time_arrived_on_site, t7_cant_find_job_time_left_site,
t8_underground_fault_supply_voltage_at_base,
t8_underground_fault_description, t8_underground_fault_contractor_name,
t8_underground_fault_contractor_phone, work_order, t1_traffic_management,
t3_material, diagram_or_photograph)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
?, ?, ?, ?, ?, ?)
java.sql.SQLException: SQL logic error or missing database
at org.sqlite.DB.throwex(DB.java:288)
at org.sqlite.DB.exec(DB.java:68)
at org.sqlite.Conn.commit(Conn.java:172)
at tabletapp.database.DB.prepareStatement(DB.java:695)
at tabletapp.database.DB.save(DB.java:778)
at tabletapp.FormPanel.saveData(FormPanel.java:627)
at tabletapp.FormView$3.actionPerformed(FormView.java:242)
at
javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
at
javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
at
javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
at
javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
at
javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
at java.awt.Component.processMouseEvent(Component.java:6263)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
at java.awt.Component.processEvent(Component.java:6028)
at java.awt.Container.processEvent(Container.java:2041)
at java.awt.Component.dispatchEventImpl(Component.java:4630)
at java.awt.Container.dispatchEventImpl(Container.java:2099)
at java.awt.Component.dispatchEvent(Component.java:4460)
at
java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4574)
at
java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
at java.awt.Container.dispatchEventImpl(Container.java:2085)
at java.awt.Window.dispatchEventImpl(Window.java:2476)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at
java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at
java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at
java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:178)
at java.awt.Dialog$1.run(Dialog.java:1045)
at java.awt.Dialog$3.run(Dialog.java:1097)
at java.security.AccessController.doPrivileged(Native Method)
at java.awt.Dialog.show(Dialog.java:1095)
at java.awt.Component.show(Component.java:1563)
at java.awt.Component.setVisible(Component.java:1515)
at java.awt.Window.setVisible(Window.java:842)
at java.awt.Dialog.setVisible(Dialog.java:985)
at
org.jdesktop.application.SingleFrameApplication.show(SingleFrameApplication.java:296)
at tabletapp.TabletApp.showEditForm(TabletApp.java:153)
at tabletapp.TableView.mainTableMouseClicked(TableView.java:517)
at tabletapp.TableView.access$700(TableView.java:39)
at tabletapp.TableView$6.mouseClicked(TableView.java:401)
at
java.awt.AWTEventMulticaster.mouseClicked(AWTEventMulticaster.java:253)
at java.awt.Component.processMouseEvent(Component.java:6266)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
at java.awt.Component.processEvent(Component.java:6028)
at java.awt.Container.processEvent(Container.java:2041)
at java.awt.Component.dispatchEventImpl(Component.java:4630)
at java.awt.Container.dispatchEventImpl(Container.java:2099)
at java.awt.Component.dispatchEvent(Component.java:4460)
at
java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4574)
at
java.awt.LightweightDispatcher.processMouseEvent(Container.java:4247)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
at java.awt.Container.dispatchEventImpl(Container.java:2085)
at java.awt.Window.dispatchEventImpl(Window.java:2476)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at
java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at
java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at
java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at
java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at
java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
</error>
And heres th full code block
<code>
public void prepareStatement(String table, String sql,
LinkedHashMap<String, String> data) {
try {
String typeID = "";
PreparedStatement ps = connection.prepareStatement(sql);
log.debug("Preparing SQL: " + sql.replace("\n", ""));
int parameterIndex = 1;
//for (String columnName : getColumnNames(table)) {
for (String columnName : data.keySet()) {
typeID = getColumnType(table, columnName);
if (data.containsKey(columnName)) {
String value = data.get(columnName);
if (value == null || "".equals(value)) {
//log.debug(columnName+":"+parameterIndex+" set to null");
ps.setNull(parameterIndex, Types.NULL);
} else {
//log.debug(columnName+":"+parameterIndex+" set to "+value);
switch (getColumnTypeId(table, columnName)) {
case Types.VARCHAR:
case Types.CHAR:
log.debug("Parameter " + parameterIndex + " = " + value);
ps.setString(parameterIndex, value);
break;
case Types.TIMESTAMP:
DateFormat timestampFormat = new SimpleDateFormat("yyyy-MM-dd
HH:mm:ss");
Timestamp timestamp = new Timestamp(new
java.util.Date().getTime());
try {
timestamp = new
Timestamp(timestampFormat.parse(value).getTime());
} catch (ParseException e) {
log.error("Unable to parse timestamp: " + value + ".");
}
log.debug("Parameter " + parameterIndex + " = " + timestamp);
ps.setTimestamp(parameterIndex, timestamp);
break;
case Types.DATE:
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
java.sql.Date date = new java.sql.Date(new
java.util.Date().getTime());
try {
timestamp = new Timestamp(dateFormat.parse(value).getTime());
} catch (ParseException e) {
log.error("Unable to parse date: " + value + ".");
}
log.debug("Parameter " + parameterIndex + " = " + date);
ps.setDate(parameterIndex, date);
break;
case Types.SMALLINT:
case Types.INTEGER:
case Types.NUMERIC:
log.debug("Parameter " + parameterIndex + " = " + value);
ps.setInt(parameterIndex, new Integer(value));
break;
case Types.FLOAT:
log.debug("Parameter " + parameterIndex + " = " + value);
ps.setFloat(parameterIndex, new Float(value));
break;
case Types.BLOB:
// convert to byte array to blob
byte[] bData;
ByteArrayInputStream bais ;
try {
bData = tabletapp.util.Base64.toBytes(value);
log.info("I have " + bData.length + " bytes in Bytes[]");
bais = new ByteArrayInputStream(bData);
//String mimeType =
//log.info("Mime types: "+mimeType);}
} catch (Exception e) {
bData = null;
log.info("Something went Horribly, Horribly Wrong");
log.info(e.getLocalizedMessage());
}
bais = new ByteArrayInputStream(bData);
log.info("Database is " + dbType);
if (dbType.equals("sqlite")) {
try {
ps.setBytes(parameterIndex, bData);
} catch (SQLException e) {
log.debug(e.getLocalizedMessage());
}
log.info("Sqlite Blob set to " + value);
} else {
ps.setBlob(parameterIndex, bais, bData.length);
}
log.debug("Parameter " + parameterIndex + " = [BLOB]");
break;
case Types.BOOLEAN:
case Types.BIT:
//log.debug(table + "." + columnName + " (boolean) = " + value);
Boolean val = ("1".equals(value) || "true".equals(value));
log.debug("Parameter " + parameterIndex + " = " + val);
ps.setBoolean(parameterIndex, val);
break;
default:
log.debug("Parameter " + parameterIndex + " = " + value);
ps.setString(parameterIndex, value);
break;
}
}
parameterIndex++;
}
}
ps.executeUpdate();
connection.commit();
} catch (SQLException e) {
log.error("Error in sql: " + sql);
e.printStackTrace();
}
}
</code>
Ulric Auger wrote:
> Having the complete stack trace of the exception would help a lot.
>
> Here are some thoughts:
> 1- You did not explicitly close the preparedstatement before calling
> commit.
> 2- You are trying to commit without having started a transaction.
>
> I don't think the problem is related to the setBytes() as I have similar
> code in my application and it work perfectly.
>
> Which version of SQLiteJDBC you are using?
>
> Ulric
>
>
>
--
Peter
_______________________________________________
sqlite-users mailing list
[email protected]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users