resultset condition

Hi

I am trying to check for records being available in my table based upon which i want to do an update or insert.

To check for this i tried getting row count for that condition

i got the row count in a variable. then if rowcount > 0

then i proceed with update or else i try the insert.But the problem is that i get a null pointer exception immedeatly after the sql where i get the row count.

How do i tackle this

sql = "select count(*) nRows from employee where dept = '10'"

rs = stmt.executeQuery(sql);

while(rs.next()) {

nRows = rs.getInt(1);

if (nRows > 0) {

perform update}

else( perform insert)

}

Thanks

Arn

[736 byte] By [arnoldfire] at [2007-9-26 6:23:07]
# 1
HiTry doing this.sql = "select * from employee where dept = '10'" rs = stmt.executeQuery(sql);while(rs.next()) {nRows = rs.getFetchSize();if (nRows > 0) {perform update}else( perform insert)}
ramau at 2007-7-1 15:24:01 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 2
Hi RamauThe problem is my jdbc driver doesnt support the fetchsize methodArn
arnoldfire at 2007-7-1 15:24:01 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 3
Are you against initialising nrows variable to zero before the recordset is fetched .
kandir at 2007-7-1 15:24:01 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 4
Which doesn't matter, because the getFetchSize() method has absolutely nothing to do with your problem. However, it would help if you showed the actual code that was throwing the NullPointerException. Your error likely has nothing to do with SQL or JDBC.
DrClap at 2007-7-1 15:24:01 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...