• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

JDBC Doubt

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:oracle: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.
 
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
resultset would never be null , even if it doesn't have any record in it.
For more information related to this check javadoc.
 
A wop bop a lu bop a womp bam boom! Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic