ERROR java.sql.SQLException: near “-”: syntax error-Collection of common programming errors
I am developing a Java tools to convert StarDict database to SQLite database for use with an Android Dictionary app. But I get the following error:
java.sql.SQLException: near "-": syntax error at
org.sqlite.DB.throwex(DB.java:288) at
org.sqlite.NativeDB.prepare(Native Method) at
org.sqlite.DB.prepare(DB.java:114) at
org.sqlite.Stmt.executeUpdate(Stmt.java:102) at
com.trivisionsc.ConvertData.createData(ConvertData.java:353) at
com.trivisionsc.ConvertData.excuteConvert(ConvertData.java:314) at
com.trivisionsc.ConvertData$1.actionPerformed(ConvertData.java:116) at
javax.swing.AbstractButton.fireActionPerformed(Unknown Source) at
javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source) at
javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source) at
javax.swing.DefaultButtonModel.setPressed(Unknown Source) at
javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source) at
java.awt.Component.processMouseEvent(Unknown Source) at
javax.swing.JComponent.processMouseEvent(Unknown Source) at
java.awt.Component.processEvent(Unknown Source) at
java.awt.Container.processEvent(Unknown Source) at
java.awt.Component.dispatchEventImpl(Unknown Source) at
java.awt.Container.dispatchEventImpl(Unknown Source) at
java.awt.Component.dispatchEvent(Unknown Source) at
java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source) at
java.awt.LightweightDispatcher.processMouseEvent(Unknown Source) at
java.awt.LightweightDispatcher.dispatchEvent(Unknown Source) at
java.awt.Container.dispatchEventImpl(Unknown Source) at
java.awt.Window.dispatchEventImpl(Unknown Source) at
java.awt.Component.dispatchEvent(Unknown Source) at
java.awt.EventQueue.dispatchEvent(Unknown Source) at
java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source) at
java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source) at
java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source) at
java.awt.EventDispatchThread.pumpEvents(Unknown Source) at
java.awt.EventDispatchThread.pumpEvents(Unknown Source) at
java.awt.EventDispatchThread.run(Unknown Source)
And here is the source:
package com.trivisionsc;
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Image;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.WindowConstants;
public class ConvertData extends JFrame
{
// Variables declaration
int count=0;
private static final long serialVersionUID = 1L;
private JLabel lblIndexFilePath;
private JLabel lblDictFilePath;
private JLabel lblDisplayProcess;
private JTextField txtSourceFilePath;
private JTextField txtDbFilePath;
private JButton btnPerform;
private JButton btnStop;
private JButton btnIndexFileSelect;
private JButton btnDictFileSelect;
private JPanel contentPane;
private JFileChooser fc;
private String messageResult;
private int start;
private int countWord;
private int numberWord;
int result;
boolean stop;
// End of variables declaration
public ConvertData()
{
super();
createLayout();
this.setVisible(true);
}
private void createLayout()
{
// Initialize
lblIndexFilePath = new JLabel();
lblDictFilePath = new JLabel();
lblDisplayProcess= new JLabel();
txtSourceFilePath = new JTextField();
txtDbFilePath = new JTextField();
btnPerform = new JButton();
btnStop=new JButton();
btnIndexFileSelect=new JButton();
btnDictFileSelect=new JButton();
contentPane = (JPanel)this.getContentPane();
fc = new JFileChooser();
fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
//lblDisplayProcess
lblDisplayProcess.setForeground(new Color(255, 0, 0));
lblDisplayProcess.setHorizontalAlignment(SwingConstants.LEFT);
//lblIndexFilePath
lblDictFilePath.setHorizontalAlignment(SwingConstants.LEFT);
lblIndexFilePath.setText(" Path store source dict");
//lblDictFilePath
lblDictFilePath.setHorizontalAlignment(SwingConstants.LEFT);
lblDictFilePath.setText(" Path store database");
// txtSourceFilePath
txtSourceFilePath.setForeground(new Color(0, 0, 255));
txtSourceFilePath.setToolTipText("Enter path store source dict");
// txtDbFilePath
txtDbFilePath.setForeground(new Color(0, 0, 255));
txtDbFilePath.setToolTipText("Enter path store database");
// btnPerform
btnPerform.setText("Convert");
btnPerform.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{
//insert database
excuteConvert();
}
});
// btnStop
btnStop.setText("Stop");
btnStop.setEnabled(false);
btnStop.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{
stop=true;
}
});
// btnIndexFileSelect
btnIndexFileSelect.setText("Browser...");
btnIndexFileSelect.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{
int returnVal = fc.showOpenDialog(ConvertData.this);
if (returnVal == JFileChooser.APPROVE_OPTION)
{
File file = fc.getSelectedFile();
txtSourceFilePath.setText(file.getAbsolutePath());
}
}
});
// btnDictFileSelect
btnDictFileSelect.setText("Browser...");
btnDictFileSelect.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{
int returnVal = fc.showOpenDialog(ConvertData.this);
if (returnVal == JFileChooser.APPROVE_OPTION)
{
File file = fc.getSelectedFile();
txtDbFilePath.setText(file.getAbsolutePath());
}
}
});
// contentPane
contentPane.setLayout(null);
contentPane.setBorder(BorderFactory.createEtchedBorder());
// add component for Frame
addComponent(contentPane, lblIndexFilePath, 35,10,126,18);
addComponent(contentPane, lblDictFilePath, 35,47,126,18);
addComponent(contentPane, txtSourceFilePath, 160,10,203,22);
addComponent(contentPane, btnIndexFileSelect, 365,9,80,25);
addComponent(contentPane, txtDbFilePath, 160,45,203,22);
addComponent(contentPane, btnDictFileSelect, 365,44,80,25);
addComponent(contentPane, btnPerform, 160,75,90,30);
addComponent(contentPane, btnStop, 250,75,90,30);
addComponent(contentPane, lblDisplayProcess, 35,110,250,18);
//set title for program
this.setTitle("Convert data for TDict");
// set icon for program
ImageIcon receivedIcon = new ImageIcon("resource\\images\\tri.png");
Image logoImg=receivedIcon.getImage();
this.setIconImage(logoImg);
//set position display
this.setLocation(new Point(400, 300));
//set size display
this.setSize(new Dimension(500, 200));
//set event close window
this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
//set disable resize
this.setResizable(false);
}
/** Add Component Without a Layout Manager (Absolute Positioning) */
private void addComponent(Container container,Component c,int x,int y,int width,int height)
{
c.setBounds(x,y,width,height);
container.add(c);
}
public void excuteConvert()
{
//set empty for display result run
lblDisplayProcess.setText("");
//name dictionary
String dictName=null;
// path to file
String sourceStorePath=txtSourceFilePath.getText();
String dbStorePath=txtDbFilePath.getText();
// path file source dictionary don't exits
File directorySource = new File(sourceStorePath);
// path file source dictionary don't exits
if (sourceStorePath==null || sourceStorePath.equals("")||!directorySource.exists())
{
JOptionPane.showMessageDialog(ConvertData.this,"Path is invalid!","Error",JOptionPane.ERROR_MESSAGE,null);
txtSourceFilePath.requestFocus();
return;
}
// path file database don't exits
File directoryDb = new File(dbStorePath);
if (dbStorePath==null || dbStorePath.equals("")||!directoryDb.exists())
{
JOptionPane.showMessageDialog(ConvertData.this,"Path is invalid!","Error",JOptionPane.ERROR_MESSAGE,null);
txtDbFilePath.requestFocus();
return;
}
// check in source directory include: file index,dictionary and information?
File[] files = directorySource.listFiles();
int check=0;
if (files.length>0)
{
for (int i = 0; i < files.length; i++)
{
if(files[i].getName().endsWith(".idx"))
{
check++;
dictName=files[i].getName().replaceAll(".idx", "");
}
if(files[i].getName().endsWith(".dict"))
check++;
if(files[i].getName().endsWith(".ifo"))
check++;
}
}
else
{
// Folder don't include any file
JOptionPane.showMessageDialog(ConvertData.this,"Source directory have to include files: .idx,.dict and .ifo","Error",JOptionPane.ERROR_MESSAGE,null);
txtSourceFilePath.requestFocus();
return;
}
if(check
Originally posted 2013-11-10 00:12:16.