+ 2
Getting column name instead of values in prepared statement
I am getting column name instead of values in prepared statement. here is my piece of code: string q="select ? from EMPLOYEE where salary>?"; prepared pst=connectionobject.preparedstatement(q); pst.setstring(1,"FIRST_NAME"); pst.setint(2,10000); please help
12 odpowiedzi
+ 1
I want to set values, I figured out a way using string concatenation but I wonder why set doesn't work properly....
+ 1
sorry I meant get...
+ 1
I don't want to get the name from resultset containing other columns instead I want the resultset to contain only the name without any other column,... if that makes sense
+ 1
just tell me how to set first "?" value correctly(that is select ? from employee where salary>?)
I am saying this because actually in my program I set the column name dynamically from jcombobox
+ 1
thanks for the reply.
by the way that's what I did string concatenation...
so you are saying there is no way we can set ? using setxxx() method
0
do you want to get or set the values? I would do it ways different
0
you need 'pst.executeUpdate()' in the end, and maybe a commit
0
statement st= st.createStatement();
ResultSet rs = st.executeQuery("SELECT * FROM EMPLOYEE WHERE salary>10000");
while(rs.hasnext())
{
string name = rs.getString("name");
.....
}
kind of this, you are trying to set the values in your code..
0
working now?
0
yeah Just change the select statement to: SELECT name FROM ..then you get just the name, but you still should use the while loop
0
easiest way is: st.executeQuery("SELECT " +column name+ " FROM EMPLOYEE WHERE salary > " + salary);
0
yes you can set values with the set method but you need to execute the set commands with executeUpdate() method in the end, but then you set the value in the database