「Java」OracleのPreparedStatement(バインド変数のサンプル

書式
where 項目名 = ?
setString(int parameterIndex, String x)
parameterIndex:パラメータ変数のインデックス
x:項目用変数名

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
public staic boolean check(Connection conn,String uid)
{
PreparedStatement pstmt = null;
ResultSet rslt = null;
try{
pstmt = conn.prepareStatement(
"select username, useraddr"
+ " from user_tbl"
+ " where uid = ?"
);
pstmt.setString(1, uid);
}catch (SQLException e){
}
//some code
}
public staic boolean check(Connection conn,String uid) { PreparedStatement pstmt = null; ResultSet rslt = null; try{ pstmt = conn.prepareStatement( "select username, useraddr" + " from user_tbl" + " where uid = ?" ); pstmt.setString(1, uid); }catch (SQLException e){ } //some code }
public staic boolean check(Connection conn,String uid)
{
  PreparedStatement pstmt = null;
  ResultSet rslt = null;

  try{ 
      pstmt = conn.prepareStatement(
                    "select username, useraddr" 
                  + "  from user_tbl"
                  + " where uid = ?"
                  );
      pstmt.setString(1, uid);
       }catch (SQLException e){
       }
      //some code
}

 

Java

Posted by arkgame