使用方法调用插入数据时出现SQLite错误

时间:2014-12-24 08:12:01

标签: java sqlite netbeans

这是我在Database类中的insert()方法:

public static void insert(String query){
    Connection con;
    Statement st;
    try{
        Class.forName("org.sqlite.JDBC");
        con = DriverManager.getConnection("jdbc:sqlite:fliplist.db");
        con.setAutoCommit(false);
        st = con.createStatement();
        st.executeUpdate(query);
        st.close();
        con.commit();
        con.close();
    } catch (ClassNotFoundException | SQLException e) {
        System.err.println(e.getMessage());
        e.printStackTrace();
    }
}

现在,当用户单击“创建新帐户”按钮时,这会将所有值插入到用户表中,这是一个SQLite数据库。

private void newAccountButtonMouseClicked(java.awt.event.MouseEvent evt) {
    String fullname = account_fullname.getText();
    String username = account_username.getText();
    String password = account_password.getText();
    String email = account_email.getText();
    Database db = new Database();
    db.insert("INSERT INTO user (fullname, username, password, email) VALUES ("+ fullname +", "+ username +","+ password +","+ email +")");
}  

这应该将所有数据插入到用户表中,但是我收到此错误:

run:
near "Kazi": syntax error
java.sql.SQLException: near "Kazi": syntax error
at org.sqlite.core.NativeDB.throwex(NativeDB.java:397)
at org.sqlite.core.NativeDB._exec(Native Method)
at org.sqlite.jdbc3.JDBC3Statement.executeUpdate(JDBC3Statement.java:116)
at FlipList.Database.insert(Database.java:29)
at FlipList.WelcomeForm.newAccountButtonMouseClicked(WelcomeForm.java:244)
at FlipList.WelcomeForm.access$000(WelcomeForm.java:14)
at FlipList.WelcomeForm$1.mouseClicked(WelcomeForm.java:64)
at java.awt.AWTEventMulticaster.mouseClicked(AWTEventMulticaster.java:270)
at java.awt.Component.processMouseEvent(Component.java:6530)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
at java.awt.Component.processEvent(Component.java:6292)
at java.awt.Container.processEvent(Container.java:2234)
at java.awt.Component.dispatchEventImpl(Component.java:4883)
at java.awt.Container.dispatchEventImpl(Container.java:2292)
at java.awt.Component.dispatchEvent(Component.java:4705)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4898)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4542)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4462)
at java.awt.Container.dispatchEventImpl(Container.java:2278)
at java.awt.Window.dispatchEventImpl(Window.java:2739)
at java.awt.Component.dispatchEvent(Component.java:4705)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:746)
at java.awt.EventQueue.access$400(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:697)
at java.awt.EventQueue$3.run(EventQueue.java:691)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:86)
at java.awt.EventQueue$4.run(EventQueue.java:719)
at java.awt.EventQueue$4.run(EventQueue.java:717)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:716)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
BUILD SUCCESSFUL (total time: 17 seconds)

我在这里做错了什么?

0 个答案:

没有答案