Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/341.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java MySQL ODBC PreparedStatement切断查询_Java_Mysql_Odbc_Prepared Statement - Fatal编程技术网

Java MySQL ODBC PreparedStatement切断查询

Java MySQL ODBC PreparedStatement切断查询,java,mysql,odbc,prepared-statement,Java,Mysql,Odbc,Prepared Statement,`我在为Java ODBC MySQL编写PreparedStatement时遇到问题。它似乎切断了查询,并给出了一个语法错误。我不知道如何继续,因为我现在只学习JavaSQL。我真的不能做一个自包含的例子,因为问题涉及数据库,而且会变得相当大 出现问题的代码如下 public void insertEntry( Hashtable<String, String> strings, Hashtable<String, Intege

`我在为Java ODBC MySQL编写PreparedStatement时遇到问题。它似乎切断了查询,并给出了一个语法错误。我不知道如何继续,因为我现在只学习JavaSQL。我真的不能做一个自包含的例子,因为问题涉及数据库,而且会变得相当大

出现问题的代码如下

public void insertEntry(
            Hashtable<String, String> strings,
            Hashtable<String, Integer> integers,
            Date created, Date paid, boolean enabled)
            throws ClassNotFoundException, SQLException {
        Class.forName("com.mysql.jdbc.Driver");

        String dburl = "jdbc:mysql://" + dbHost + "/" + dbName +
                        "?user=" + dbUser + "&password=" + dbPass;

        connect = DriverManager.getConnection(dburl);

        ps = connect.prepareStatement("INSERT INTO " + dbName + ".users INSERT " +
                "enabled=?, username=?, created=?, paid=?, alias=?, password=?, " +
                "email=?, bitmessage=?, torchat=?, reputation=?," +
                "privacy=?, fpmport=?, fpm-template=? ;");

        java.sql.Date SQLcreated = new java.sql.Date(created.getTime());
        java.sql.Date SQLpaid = new java.sql.Date(paid.getTime());
        System.out.println("Debug: SQLpaid = " + SQLpaid.toString());

        ps.setBoolean(1, enabled);
        ps.setString(2, strings.get("username"));
        ps.setDate(3, SQLcreated);
        ps.setDate(4, SQLpaid);
        ps.setString(5, strings.get("alias"));
        ps.setString(6, strings.get("password"));
        ps.setString(7, strings.get("email"));
        ps.setString(8, strings.get("bitmessage"));
        ps.setString(9, strings.get("torchat"));
        ps.setInt(10, integers.get("reputation"));
        ps.setInt(11, integers.get("privacy"));
        ps.setInt(12, integers.get("fpmport"));
        ps.setString(13, strings.get("fpm-template"));
        ps.executeUpdate();

        ps.close();
        connect.close();
        resultSet.close();
    }
更改:

INSERT INTO " + dbName + ".users INSERT "
致:

请参阅

插入[低优先级|延迟|高优先级][忽略]
[INTO]tbl_名称
[分区(分区名称,…)
设置col_name={expr | DEFAULT},…
[在重复密钥更新时
col_name=expr
[,col_name=expr]…]

我认为您在代码中犯了一些错误:

这些措施如下:

1。你提到的
插入
,你必须像
设置

 ps = connect.prepareStatement
 ("INSERT INTO " + dbName + ".users  INSERT " #look here error to change 'set' +
  "enabled=?, username=?, created=?, paid=?, alias=?, password=?, " +
  "email=?, bitmessage=?, torchat=?, reputation=?," +
  "privacy=?, fpmport=?, fpm-template=?  ; " #remove this semicolon(;));
 ps = connect.prepareStatement
           ("INSERT INTO " + dbName + ".users SET " +
           "enabled=?, username=?, created=?, paid=?, alias=?, password=?, " +
           "email=?, bitmessage=?, torchat=?, reputation=?," +
           "privacy=?, fpmport=?, fpm-template=? ");
2。添加
在SQL查询中,您应该删除它。

您的代码:

您必须像这样更改:


这是什么
users INSERT
INSERT agian?@sankrish:不是。除了有一个小错误。谢谢你的回答,帮助我解决了我的问题:有些语句在SQL查询末尾不能有分号,否则如果在一个批中分组多个查询,MySQL将失败,并出现与上述相同的错误。
 ps = connect.prepareStatement
 ("INSERT INTO " + dbName + ".users  INSERT " #look here error to change 'set' +
  "enabled=?, username=?, created=?, paid=?, alias=?, password=?, " +
  "email=?, bitmessage=?, torchat=?, reputation=?," +
  "privacy=?, fpmport=?, fpm-template=?  ; " #remove this semicolon(;));
 ps = connect.prepareStatement
           ("INSERT INTO " + dbName + ".users SET " +
           "enabled=?, username=?, created=?, paid=?, alias=?, password=?, " +
           "email=?, bitmessage=?, torchat=?, reputation=?," +
           "privacy=?, fpmport=?, fpm-template=? ");