Parameter « JDBC « Java Database Q&A





1. In JDBC, why do parameter indexes for prepared statements begin at 1 instead of 0?    stackoverflow.com

Everywhere else in Java, anything with an index starts at 0. Is there a reason for the change here or is this just bad design?

2. Prepared statement. Can I miss out parameter?    stackoverflow.com

I use queries like

"UPDATE MAILSCH.MESSAGE "
            + "SET IDFOLDER=?, SUBJECT=?, CONTENT=?, CREATIONTIME=?, AD_FROM=?, AD_TO=?, STATUS=? "
    ...

3. Clever way to add the same parameter to mulitple locations in a prepared-statement    stackoverflow.com

I have a JDBC query like

select * from table1 where col1 between x and y
union all
select * from table2 where col1 between x and y
union all
select * from table3 where col1 ...

5. Using PreparedStatement when the number of parameters will only be known at runtime    coderanch.com

How do you use PreparedStatement for queries in which you do not how many parameters you will need until runtime. Say, you have 3 optional parameters, you dont know which ones or how many the user will specify until runtime, but if they are set they have to be included. This is how I am doing it now. _____________________________________________ /* These ...

6. How to pass parameter to CachedRowSet    coderanch.com

7. passing parameters using Prepared Statement    coderanch.com

public List getKw(String kw) throws SQLException { if(kw == null || kw.length() == 0) throw new SQLException(ResourceManager.getString("retrieve.kw.null")); Connection connection = getConnection(); PreparedStatement pstmt = connection.prepareStatement("select * from xyz where ItemName like('%?%');"); pstmt.setString(1,kw); ResultSet rs =pstmt.executeQuery(); List list = new ArrayList(); InfyCrDao ic = null; if(rs.next()) { ic = new InfyCrDao(rs.getInt("Sno")); ic.setSNo(rs.getInt("Sno")); ic.setItemName(rs.getString("ItemName")); ic.setItemDescription(rs.getString("ItemDescription")); ic.setDateOfInitiation(rs.getDate("DateOfInitiation")); ic.setCurrentStatus(rs.getString("CurrentStatus")); ic.setPendingWith(rs.getString("PendingWith")); ic.setRemarks(rs.getString("Remarks")); list.add(ic); } rs.close(); pstmt.close(); ...

8. Set parameter not working in the PreparedStatement , why?    coderanch.com

Not sure why my SQL is not working properly after I set parameters in the SQL instead of put variable . The following is my new code. String HOLDINGS_QUERY = "select holding_name, holding_value, as_of_date " + "from fund_grp_holding " + "where holding_type = ? " + " and fund_grp = ? order by ? " ; stmt = conn.prepareStatement(HOLDINGS_QUERY); stmt.setInt(1, type); ...

9. PreparedStatement, addBatch() and setting parameters    java-forums.org

Hi, I am trying PreparedStatement's addBatch(String sql) method. I am trying to execute two(2) Insert statement. But I am a little confuse how would I set the values for parameters in two insert statement. Trying to google it but I did not see any example that uses more than one insert statement in one preparedstatement. Here is what I am trying ...





10. Prepared Statement invalid parameter index    forums.oracle.com