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

[505 byte] By [GloomyProgrammera] at [2007-11-27 5:29:35]
# 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.

BalusCa at 2007-7-12 14:52:56 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 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.
masijade.a at 2007-7-12 14:52:56 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...