I am trying to run the following query.
select emp_id, emp_fName, emp_lName from
employee where emp_lName = 'ABC' and emp_status='ACT';
I should get at least one row from the database(as there is data) but I am not getting any data when using PreparedStatement. Following is the
Jdbc code to access the same. ( Not the actual code but similar snippet. )
Connection conn = null;
PreparedStatement stmt = null;
List rslts = new ArrayList();
String sql="select emp_id, emp_fName, emp_lName, emp_status from employee e where e.emp_lName = ? and emp_status = ?";
try {
conn = -- get the connection from connection Pool (oracle thin driver and server is weblogic 7) --
stmt = conn.prepareStatement(sql);
stmt.setString( 1, "ABC" );
stmt.setString( 2, "ACT" );
ResultSet rs = stmt.executeQuery();
while( rs.next() ) {
rslts.add(rs.getString(1));
}
rs.close();
With this I do not get any rows. There is no syntax errors. no other errors, if I hardcode the last name in sql query, it works and returns the resulting row.
The oracle database table is structured as follows
emp_lName - char(15)
emp_status - char(3)
If I pad the lastname to 15 chars to mimic the data structure of last_name column, then it works. i.e if I do something like stmt.setString( 1, "ABC############" ); (substitute # with space. Couldnt show space. whitespace is trimmed) then it works Sorry for the bold but Its a long question and wanted to catch your attention
Is this something wrong with Jdbc PreparedStatement binding? if so what is the workaround for that?
[ August 22, 2007: Message edited by: chetak faldesai ]