Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/325.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更新_Java_Mysql_Jdbc_Sql Update - Fatal编程技术网

java mysql更新

java mysql更新,java,mysql,jdbc,sql-update,Java,Mysql,Jdbc,Sql Update,我在执行java类更新mysql数据库时出现了这个错误 com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'usage = 6000 where user_id =

我在执行java类更新mysql数据库时出现了这个错误

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in
your SQL syntax; check the manual that corresponds to your MySQL server version
for the right syntax to use near 'usage = 6000 where user_id = 1 and api_id = 1'
 at line 1
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstruct
orAccessorImpl.java:39)..
代码如下:

int u_id=1;
int a_id=1;

String url = "jdbc:mysql://localhost:3306/new_db";
String driver = "com.mysql.jdbc.Driver";
String userName = "root";
String password = "1234";
int APIusage = 0;


try {
    Class.forName(driver).newInstance();

    Connection conn = DriverManager.getConnection(url, userName, password);
    String query = "update api_consume set usage = ? where user_id = ? and api_id = ?";
    PreparedStatement preparedStmt = conn.prepareStatement(query);
    preparedStmt.setInt(1, 6000);
    preparedStmt.setInt(2, u_id);
    preparedStmt.setInt(3, a_id);

    // execute the java preparedstatement
    preparedStmt.executeUpdate();

    conn.close();
} 
catch (Exception e) {
      e.printStackTrace();
}
你能看看为什么会有语法错误吗?
感谢

用法
在MySQL中是一个,因此您需要引用它:

String query = "update api_consume set `usage` = ? where user_id = ? and api_id = ?";

用法
是MySQL中的一个,因此您需要引用它:

String query = "update api_consume set `usage` = ? where user_id = ? and api_id = ?";

这是因为
用法
关键字。将该列名称更改为usage\u msg或其他名称。

这是因为
usage
关键字。将该列名更改为usage\u msg或其他名称