{"id":1252,"date":"2022-08-30T15:14:55","date_gmt":"2022-08-30T15:14:55","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/10\/error-java-sql-sqlexception-near-syntax-error-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:14:55","modified_gmt":"2022-08-30T15:14:55","slug":"error-java-sql-sqlexception-near-syntax-error-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/error-java-sql-sqlexception-near-syntax-error-collection-of-common-programming-errors\/","title":{"rendered":"ERROR java.sql.SQLException: near &ldquo;-&rdquo;: syntax error-Collection of common programming errors"},"content":{"rendered":"<p>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:<\/p>\n<pre><code>java.sql.SQLException: near \"-\": syntax error at\norg.sqlite.DB.throwex(DB.java:288) at\norg.sqlite.NativeDB.prepare(Native Method) at\norg.sqlite.DB.prepare(DB.java:114) at\norg.sqlite.Stmt.executeUpdate(Stmt.java:102) at\ncom.trivisionsc.ConvertData.createData(ConvertData.java:353) at\ncom.trivisionsc.ConvertData.excuteConvert(ConvertData.java:314) at\ncom.trivisionsc.ConvertData$1.actionPerformed(ConvertData.java:116) at\njavax.swing.AbstractButton.fireActionPerformed(Unknown Source) at\njavax.swing.AbstractButton$Handler.actionPerformed(Unknown Source) at\njavax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source) at\njavax.swing.DefaultButtonModel.setPressed(Unknown Source) at\njavax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source) at\njava.awt.Component.processMouseEvent(Unknown Source) at\njavax.swing.JComponent.processMouseEvent(Unknown Source) at\njava.awt.Component.processEvent(Unknown Source) at\njava.awt.Container.processEvent(Unknown Source) at\njava.awt.Component.dispatchEventImpl(Unknown Source) at\njava.awt.Container.dispatchEventImpl(Unknown Source) at\njava.awt.Component.dispatchEvent(Unknown Source) at\njava.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source) at\njava.awt.LightweightDispatcher.processMouseEvent(Unknown Source) at\njava.awt.LightweightDispatcher.dispatchEvent(Unknown Source) at\njava.awt.Container.dispatchEventImpl(Unknown Source) at\njava.awt.Window.dispatchEventImpl(Unknown Source) at\njava.awt.Component.dispatchEvent(Unknown Source) at\njava.awt.EventQueue.dispatchEvent(Unknown Source) at\njava.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source) at\njava.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source) at\njava.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source) at\njava.awt.EventDispatchThread.pumpEvents(Unknown Source) at\njava.awt.EventDispatchThread.pumpEvents(Unknown Source) at\njava.awt.EventDispatchThread.run(Unknown Source)\n<\/code><\/pre>\n<p>And here is the source:<\/p>\n<pre><code>package com.trivisionsc;\n\nimport java.awt.Color;\nimport java.awt.Component;\nimport java.awt.Container;\nimport java.awt.Dimension;\nimport java.awt.Image;\nimport java.awt.Point;\nimport java.awt.event.ActionEvent;\nimport java.awt.event.ActionListener;\nimport java.io.BufferedInputStream;\nimport java.io.BufferedReader;\nimport java.io.DataInputStream;\nimport java.io.File;\nimport java.io.FileInputStream;\nimport java.io.InputStreamReader;\nimport java.sql.Connection;\nimport java.sql.DriverManager;\nimport java.sql.Statement;\n\nimport javax.swing.BorderFactory;\nimport javax.swing.ImageIcon;\nimport javax.swing.JButton;\nimport javax.swing.JDialog;\nimport javax.swing.JFileChooser;\nimport javax.swing.JFrame;\nimport javax.swing.JLabel;\nimport javax.swing.JOptionPane;\nimport javax.swing.JPanel;\nimport javax.swing.JTextField;\nimport javax.swing.SwingConstants;\nimport javax.swing.SwingUtilities;\nimport javax.swing.UIManager;\nimport javax.swing.WindowConstants;\n\n\npublic class ConvertData extends JFrame\n\n{\n  \/\/ Variables declaration\n  int count=0;\n  private static final long serialVersionUID = 1L;\n  private JLabel lblIndexFilePath;\n  private JLabel lblDictFilePath;\n  private JLabel lblDisplayProcess;\n  private JTextField txtSourceFilePath;\n  private JTextField txtDbFilePath;\n  private JButton btnPerform;\n  private JButton btnStop;\n  private JButton btnIndexFileSelect;\n  private JButton btnDictFileSelect;\n  private JPanel contentPane;\n  private JFileChooser fc;\n  private String messageResult;\n  private int start;\n  private int countWord;\n  private int numberWord;\n  int result;\n  boolean stop;\n\n  \/\/ End of variables declaration\n\n  public ConvertData()\n\n  {\n    super();\n    createLayout();\n    this.setVisible(true);\n\n  }\n\n\n  private void createLayout()\n\n  {\n\n    \/\/ Initialize\n    lblIndexFilePath = new JLabel();\n    lblDictFilePath = new JLabel();\n    lblDisplayProcess= new JLabel();\n    txtSourceFilePath = new JTextField();\n    txtDbFilePath = new JTextField();\n    btnPerform = new JButton();\n    btnStop=new JButton();\n    btnIndexFileSelect=new JButton();\n    btnDictFileSelect=new JButton();\n       contentPane = (JPanel)this.getContentPane();\n      fc = new JFileChooser();\n      fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);\n       \/\/lblDisplayProcess\n      lblDisplayProcess.setForeground(new Color(255, 0, 0));\n    lblDisplayProcess.setHorizontalAlignment(SwingConstants.LEFT);\n\n    \/\/lblIndexFilePath\n    lblDictFilePath.setHorizontalAlignment(SwingConstants.LEFT);\n    lblIndexFilePath.setText(\" Path store source dict\");\n\n    \/\/lblDictFilePath\n    lblDictFilePath.setHorizontalAlignment(SwingConstants.LEFT);\n    lblDictFilePath.setText(\" Path store database\");\n\n    \/\/ txtSourceFilePath\n    txtSourceFilePath.setForeground(new Color(0, 0, 255));\n    txtSourceFilePath.setToolTipText(\"Enter path store source dict\");\n\n    \/\/ txtDbFilePath\n    txtDbFilePath.setForeground(new Color(0, 0, 255));\n    txtDbFilePath.setToolTipText(\"Enter path store database\");\n\n    \/\/ btnPerform\n    btnPerform.setText(\"Convert\");\n    btnPerform.addActionListener(new ActionListener(){\n      public void actionPerformed(ActionEvent e)\n\n      {\n         \/\/insert database\n         excuteConvert();\n      }\n\n      });\n    \/\/ btnStop\n    btnStop.setText(\"Stop\");\n    btnStop.setEnabled(false);\n    btnStop.addActionListener(new ActionListener(){\n      public void actionPerformed(ActionEvent e)\n\n      {\n        stop=true;\n      }\n\n      });\n\n    \/\/ btnIndexFileSelect\n    btnIndexFileSelect.setText(\"Browser...\");\n    btnIndexFileSelect.addActionListener(new ActionListener(){\n      public void actionPerformed(ActionEvent e)\n\n      {\n        int returnVal = fc.showOpenDialog(ConvertData.this);\n\n\n              if (returnVal == JFileChooser.APPROVE_OPTION)\n              {\n                  File file = fc.getSelectedFile();\n                  txtSourceFilePath.setText(file.getAbsolutePath());\n\n              }\n      }\n\n      });\n    \/\/ btnDictFileSelect\n    btnDictFileSelect.setText(\"Browser...\");\n    btnDictFileSelect.addActionListener(new ActionListener(){\n      public void actionPerformed(ActionEvent e)\n\n      {\n        int returnVal = fc.showOpenDialog(ConvertData.this);\n\n              if (returnVal == JFileChooser.APPROVE_OPTION)\n              {\n                  File file = fc.getSelectedFile();\n                  txtDbFilePath.setText(file.getAbsolutePath());\n              }\n      }\n\n      });  \n\n    \/\/ contentPane\n    contentPane.setLayout(null);\n    contentPane.setBorder(BorderFactory.createEtchedBorder());\n    \/\/ add component for Frame\n    addComponent(contentPane, lblIndexFilePath, 35,10,126,18);\n    addComponent(contentPane, lblDictFilePath, 35,47,126,18);\n    addComponent(contentPane, txtSourceFilePath, 160,10,203,22);\n    addComponent(contentPane, btnIndexFileSelect, 365,9,80,25);\n    addComponent(contentPane, txtDbFilePath, 160,45,203,22);\n    addComponent(contentPane, btnDictFileSelect, 365,44,80,25);\n    addComponent(contentPane, btnPerform, 160,75,90,30);\n    addComponent(contentPane, btnStop, 250,75,90,30);\n    addComponent(contentPane, lblDisplayProcess, 35,110,250,18);\n\n    \/\/set title for program\n    this.setTitle(\"Convert data for TDict\");\n    \/\/ set icon for program\n    ImageIcon receivedIcon = new ImageIcon(\"resource\\\\images\\\\tri.png\");\n    Image logoImg=receivedIcon.getImage();\n    this.setIconImage(logoImg);\n    \/\/set position display\n    this.setLocation(new Point(400, 300));\n    \/\/set size display\n    this.setSize(new Dimension(500, 200));\n    \/\/set event close window\n    this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);\n    \/\/set disable resize\n    this.setResizable(false);\n\n  }\n\n\n  \/** Add Component Without a Layout Manager (Absolute Positioning) *\/\n\n  private void addComponent(Container container,Component c,int x,int y,int width,int height)\n\n  {\n    c.setBounds(x,y,width,height);\n    container.add(c);\n  }\n  public void excuteConvert()\n  {\n    \/\/set empty for display result run\n    lblDisplayProcess.setText(\"\");  \n       \/\/name dictionary\n       String dictName=null;\n       \/\/ path to file\n       String sourceStorePath=txtSourceFilePath.getText();\n    String dbStorePath=txtDbFilePath.getText();\n    \/\/ path file source dictionary don't exits\n    File directorySource = new File(sourceStorePath);  \n\n    \/\/ path file source dictionary don't exits\n    if (sourceStorePath==null || sourceStorePath.equals(\"\")||!directorySource.exists())\n    {\n      JOptionPane.showMessageDialog(ConvertData.this,\"Path is invalid!\",\"Error\",JOptionPane.ERROR_MESSAGE,null);\n      txtSourceFilePath.requestFocus();\n      return;\n    }\n\n    \/\/ path file database don't exits\n    File directoryDb = new File(dbStorePath);  \n    if (dbStorePath==null || dbStorePath.equals(\"\")||!directoryDb.exists())\n    {\n      JOptionPane.showMessageDialog(ConvertData.this,\"Path is invalid!\",\"Error\",JOptionPane.ERROR_MESSAGE,null);\n      txtDbFilePath.requestFocus();\n      return;\n    }  \n\n    \/\/ check in source directory include: file index,dictionary and information?\n    File[] files = directorySource.listFiles();  \n    int check=0;\n    if (files.length&gt;0)\n    {\n      for (int i = 0; i &lt; files.length; i++)  \n      {  \n        if(files[i].getName().endsWith(\".idx\"))\n        {\n          check++;\n          dictName=files[i].getName().replaceAll(\".idx\", \"\");\n        }\n        if(files[i].getName().endsWith(\".dict\"))\n          check++;\n        if(files[i].getName().endsWith(\".ifo\"))\n          check++;\n      }\n    }\n    else\n    {\n      \/\/ Folder don't include any file\n      JOptionPane.showMessageDialog(ConvertData.this,\"Source directory have to include files: .idx,.dict and .ifo\",\"Error\",JOptionPane.ERROR_MESSAGE,null);\n      txtSourceFilePath.requestFocus();\n      return;\n    }\n    if(check<\/code><\/pre>\n<p id=\"rop\"><small>Originally posted 2013-11-10 00:12:16. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>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 &#8220;-&#8220;: 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) [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1252","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1252","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=1252"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1252\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=1252"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=1252"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=1252"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}