problem in jdbc preparestatement

Posted by akshay on Stack Overflow See other posts from Stack Overflow or by akshay
Published on 2010-05-17T12:05:52Z Indexed on 2010/05/17 12:10 UTC
Read the original article Hit count: 148

Filed under:
|

i am geting error when i try to use following,why is it so?

ResultSet findByUsername(String tablename,String field,String value)
{ 
    pStmt = cn.prepareStatement("SELECT * FROM" + tablename +" WHERE ? = ? ");
    pStmt.setString(1, tablename);
    pStmt.setString(2,field);
    pStmt.setString(3,value);
    return(pStmt.executeQuery());

}

also i tried following , but its not working too

ResultSet findByUsername(String tablename,String field,String value)
{ 
    String sqlQueryString = " SELECT * FROM " + tablename +" WHERE " + filed + "= ? ")     
    cn.prepareStatement(sqlQuery);
    pStmt.setString(1, value);
    return(pStmt.executeQuery());

}

© Stack Overflow or respective owner

Related posts about java

Related posts about jdbc