Regarding Preparedstatement and ResultSet
Hi All,
I am using a select statement in my program
like
select ename ,dob from emp where empno = ?.....for this I will have to use PreparedStatement ......
but how do i fetch the values of ename and dob in variable after
setInt(1,empno)
previously i had used ResultSet to store the ename and dob ,but then the select statement was completely know ....now the select stmt changes with empno....
can someone suggest away to do it ?
ta
sunny
# 1
Have you tried it? If so, which problems are you occurring then?
The handling of the ResultSet doesn't differ from that of a plain Statement. It's all about the selected columns you have specified in the SELECT part of the query, which are 'ename' and 'dob' in this case. So just use resultSet.getString("ename") and getString("dob").
Also see http://java.sun.com/docs/books/tutorial/jdbc/basics/prepared.html for a PreparedStatement tutorial.
# 2
The same way you do with Statement. You execute the statement and retrieve the result set and read it. According to your post, you know how to do that with a Statement, so do it with the PreparedStatement.