PreparedStatement SetString不起作用(例如Oracle)

时间:2014-11-06 03:22:47

标签: sql jdbc prepared-statement

我不知道为什么这个方法会出错

public TdPegawai getTdPegawai(String nip) throws Exception {
    PreparedStatement ps = null;
    try {
        TdPegawai tp = new TdPegawai();
        sql = "select * "
              "from TD_PEGAWAI " + 
              "where NIP=? "; 
        ps = connection.prepareStatement(sql);
        ps.setString(1, nip);

        ResultSet rs = ps.executeQuery();
        while (rs.next()) {
            // tp.setblablabla();
        }
        rs.close();

        return tp;
    } finally {
        ConnectionUtil.closePreparedStatement(ps);
    }
}

我的SQL变量只返回SELECT * FROM TD_PEGAWAI WHERE NIP=?

我的nip变量可以返回一个值。
我的preparestatement或setstring有什么问题吗?

0 个答案:

没有答案
相关问题