Android 如何在mysql数据库中更新查询
我正在尝试用以下代码更新mysql数据库 当我运行该程序时,控制台中出现以下错误Android 如何在mysql数据库中更新查询,android,mysql,Android,Mysql,我正在尝试用以下代码更新mysql数据库 当我运行该程序时,控制台中出现以下错误 错误: 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 'SET AVG_COST = 100000 , RWDS_INCENT = 200 , OTH_EXPENSES = 10000 ,
错误:
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
'SET AVG_COST = 100000 , RWDS_INCENT = 200 , OTH_EXPENSES = 10000 ,
TRAVELLING_EX' at line 1
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection(DB_URL,"root","root");
System.out.println("Remote DB connection established");
PreparedStatement statement=con.prepareStatement("UPDATE TBL_MONTHLY_EXPENSES_DETAILS " +
"SET AVG_COST = "+AVG_COST+" ," +
" RWDS_INCENT = "+RWDS_INCENT +" ,"+
" OTH_EXPENSES = "+OTH_EXPENSES+" ,"+
" TRAVELLING_EXPENSES = "+TRAVELLING_EXPENSES+" ,"+
" CLIENT_VISITS = "+CLIENT_VISITS+" ,"+
" REV_RECD = "+REV_RECD+" "
+" WHERE PJT_CODE = '"+PJT_CODE
+"' AND PJT_MONTH = '"+PJT_MONTH
+"' AND PJT_YEAR = '"+PJT_YEAR+"' "
);
statement.executeUpdate();
代码:
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
'SET AVG_COST = 100000 , RWDS_INCENT = 200 , OTH_EXPENSES = 10000 ,
TRAVELLING_EX' at line 1
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection(DB_URL,"root","root");
System.out.println("Remote DB connection established");
PreparedStatement statement=con.prepareStatement("UPDATE TBL_MONTHLY_EXPENSES_DETAILS " +
"SET AVG_COST = "+AVG_COST+" ," +
" RWDS_INCENT = "+RWDS_INCENT +" ,"+
" OTH_EXPENSES = "+OTH_EXPENSES+" ,"+
" TRAVELLING_EXPENSES = "+TRAVELLING_EXPENSES+" ,"+
" CLIENT_VISITS = "+CLIENT_VISITS+" ,"+
" REV_RECD = "+REV_RECD+" "
+" WHERE PJT_CODE = '"+PJT_CODE
+"' AND PJT_MONTH = '"+PJT_MONTH
+"' AND PJT_YEAR = '"+PJT_YEAR+"' "
);
statement.executeUpdate();
差旅费可能有问题。检查您试图更新的值。我还想知道在mysql数据库中插入相同值的查询。我想在mysql中插入与上述相同的数据(更新查询)。在更新查询中要修改哪些内容?行:插入TBL\u每月费用详细信息(平均成本、RWD费用)值(1、2)
。自己添加更多的列和值,您应该遵循这个模式。