| Author |
JDBC Doubt
|
ChakraPani Margani
Greenhorn
Joined: Aug 19, 2007
Posts: 15
|
|
Hai members, First of all thanking you to all of members to sending response to my previous doubts. I have some problem with the following code. Though it is compiling and running, it gives false results. First of all CODE is: ----------------------- import java.sql.*; public class sample { public void testing(String uin) { ResultSet rs=null; Statement st=null; Connection con=null; PreparedStatement ps=null; String UIN=uin; int r=0; try { Class.forName("oracle.jdbc.driver.OracleDriver"); System.out.println("DriverLoaded"); con=DriverManager.getConnection("jdbc racle:thin:@localhost:1521:Oracle","scott","tiger"); System.out.println("Connection established"); st=con.createStatement(); rs=st.executeQuery("select * from uin where NUM='"+ UIN +"'"); if(rs!=null) { System.out.println("Record is already exist"); } else { ps=con.prepareStatement("insert into uin values(?)"); ps.setString(1,UIN); r=ps.executeUpdate(); } if(r>0) { System.out.println("Number inserted Successfully:"); } rs.close(); con.close(); }//try catch(Exception e) { e.printStackTrace(); }//catch }//testing() public static void main(String args[]) { sample s=new sample(); s.testing("s7048223a"); }//main() }//class The above code is working.It always displays "Record is already exist". If i doesn't have any records in my database it always dispalys the above code. But i doesn't know wheter it is coding problem or driver problem. But remainig JDBC programs are working properly in my system. please clarify my doubt. Regards, ChakraPani.
|
 |
Rahul Bhattacharjee
Ranch Hand
Joined: Nov 29, 2005
Posts: 2300
|
|
resultset would never be null , even if it doesn't have any record in it. For more information related to this check javadoc.
|
Rahul Bhattacharjee
LinkedIn - Blog
|
 |
 |
|
|
subject: JDBC Doubt
|
|
|