-1

こんにちは、MySQL データベースに値を挿入し、以下にコードを添付したいのですが、エラーが発生しています。


try{
     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("INSERT INTO TBL_MONTHLY_EXPENSES_DETAILS"+
     (AVG_COST, RWDS_INCENT,OTH_EXPENSES,TRAVELLING_EXPENSES,CLIENT_VISITS,REV_RECD)VALUES
     (AVG_COST, RWDS_INCENT,OTH_EXPENSES,TRAVELLING_EXPENSES,CLIENT_VISITS,REV_RECD);
}catch(Exception e){
     System.out.println("Remote DataBase connection establishment error.");
     e.printStackTrace();
     pn.setProjectName("Failed");
     System.out.println(e.getMessage().toString());
}
4

2 に答える 2

1

以下の修正 - いくつかの引用符が欠落しており、正しくパラメーター化されていませんでした。

try
        {
            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("INSERT INTO TBL_MONTHLY_EXPENSES_DETAILS"+
                    "(AVG_COST, RWDS_INCENT,OTH_EXPENSES,TRAVELLING_EXPENSES,CLIENT_VISITS,REV_RECD)VALUES"+
                    "(?,?,?,?,?,?)");


    }catch(Exception e)
    {
        System.out.println("Remote DataBase connection establishment error.");
        e.printStackTrace();
        pn.setProjectName("Failed");
        System.out.println(e.getMessage().toString());
    }

statement.setX() 関数を使用して、各 ? の値を設定することを忘れないでください。VALUES ステートメントで。

于 2013-09-30T17:56:52.630 に答える
0
int AVG_COST, RWDS_INCENT, OTH_EXPENSES, TRAVELLING_EXPENSES,CLIENT_VISITS, REV_RECD;

PreparedStatement statement=conn.prepareStatement("INSERT INTO TBL_MONTHLY_EXPENSES_DETAILS" +
            "(AVG_COST, RWDS_INCENT,OTH_EXPENSES,TRAVELLING_EXPENSES,CLIENT_VISITS,REV_RECD)" +
            "VALUES(?,?,?,?,?,?)"); 

statement.setInt(1, AVG_COST);
statement.setInt(2, RWDS_INCENT);
statement.setInt(3, OTH_EXPENSES);
statement.setInt(4, TRAVELLING_EXPENSES);
statement.setInt(5, CLIENT_VISITS);
statement.setInt(6, REV_RECD);
statement.executeUpdate();
于 2013-09-30T18:01:51.077 に答える