sql - how can i check there is a record and get record values from the database using single result set in java? -
how can check there record , value database using single resultset in java...
i'm using code check there record in database or not..
then i'm record set values it's not fetch second row values... display 1 row values... give me solution....
try { class.forname("sun.jdbc.odbc.jdbcodbcdriver"); connection conn = drivermanager.getconnection("jdbc:odbc:mobile","",""); string qry = "select * login"; resultset rs = stmt.executequery(qry); if (rs.next()) { while(rs.next()) { system.out.println(rs.getstring("value1"); system.out.println(rs.getstring("value2"); } } else { system.out.println("no records"); } } catch(exception e) { system.out.println(e); }
try this:
if want trigger whether there records exist in database or not:
if (!rs.next()) { system.out.println("no records found"); } else { while(rs.next()) { system.out.println(rs.getstring("value1"); system.out.println(rs.getstring("value2"); } }
if don't want trigger whether there records exist in database or not following enough:
while(rs.next()) { system.out.println(rs.getstring("value1"); system.out.println(rs.getstring("value2"); }
update1 try this:
try { pstmt = con.preparestatement("select * login", resultset.type_scroll_insensitive,resultset.concur_updatable); rs = pstmt.executequery(); if (!rs.next()) { system.out.println("no records found"); } else { rs.beforefirst(); while(rs.next()) { system.out.println(rs.getstring("value1"); system.out.println(rs.getstring("value2"); } } }
Comments
Post a Comment