1

列の型を知らなくても、preparedstatement/statement を使用して jdbc 更新クエリを実行する必要があります。「 update table set status=? 」というクエリがあります。id=? ' {("status"="123"), ("id"="546")} のような値のマップを取得しています

列の型がわかりません。jdbc を使用してこのクエリを実行する一般的な方法はありますか?

実行する代わりに- ps.setString(1,map.get(("status")); DBのステータスフィールドの列タイプがわからないため(intの可能性もあります)

春のjdbcテンプレートを使用せずにこれを解決するのを手伝ってください。

4

1 に答える 1

0

ps.setString(1,map.get(("status"))整数でも機能します。value整数列に入れているのはint型であることに注意する必要があります。

次のコードは、次のことを説明しています。

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;


public class SOJDBC 
{
public static void main(String rgs[])
{
    Connection con = DBConnection.getConnection("TEMP");
    try 
    {
        PreparedStatement pstmt = con.prepareStatement("insert into STUDENT(ROLLNO,NAME,AGE) values(?,?,?)");
        pstmt.setString(1, "1");    //column type is integer, will work because the value is of int type
        pstmt.setString(2, "Bhushan");
        pstmt.setString(3, "25");   //column type is integer, will work because the value is of int type
        pstmt.executeUpdate();
    }
    catch (SQLException e) 
    {
        e.printStackTrace();
    }
}
}
于 2013-02-12T04:03:25.907 に答える