0
我有這樣的事情在我的sql查詢SQL準備好的語句不採用'?'在where子句
private static final String QUERY_PHYSICIAN_INFO= "SELECT * FROM PHYSICIAN_INFO WHERE ? = ?";
,但以下情況不工作雙方..
Connection conn = null;
PreparedStatement stmt = null;
String logintype;
if(isInteger(id))
{
logintype="BADGEID";
}else{
logintype="ID";
}
stmt=conn.prepareStatement(QUERY_PHYSICIAN_INFO);
stmt.setString(1, logintype);
stmt.setString(2, id);
ResultSet rs = stmt.executeQuery();
Physician phs = null;
對此有什麼特殊原因嗎? 在此先感謝。
非常感謝您的關注,我試過這種方式,但它是靜態SQL查詢更新爲空。字符串logintype; String query =「SELECT * FROM PHYSICIAN_INFO WHERE」+ logintype +「=?」現在在某些方法中,我更新logintype爲其他值,最後生成的查詢是SELECT * FROM PHYSICIAN_INFO WHERE null =? – user1065490
您需要更改SQL字符串,一旦您確定了什麼logintype是 – podiluska