Hai to all members,
First of all thanks to krishnamoorthy for sending answer to my problem.
Today i got another doubt.
My aim is to insert a
string in the data base.If that number is already
in the table then i have to display a message like number is already in the table.Otherwise number is to be inserted in the table.
I have developed code on my own.while running the code i got an exception.
I am sending the code with error message.please help me to solve this problem.
CODE IS
----------
import java.sql.*;
class
test {
public void test1(String UIN)
{
ResultSet rs=null;
Statement st=null;
Connection con=null;
PreparedStatement ps=null;
String name="";
boolean flag1=false;
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
System.out.println("DriverLoaded");
con=DriverManager.getConnection("jdbc
racle:thin:@localhost:1521
racle","scott","tiger");
System.out.println("Connection established");
st=con.createStatement();
rs=st.executeQuery("select *from uin");
if(rs!=null)
{
while(rs.next())
{
name=rs.getString(1);
if(name.equalsIgnoreCase(UIN))
flag1=true;
}
}
if(!flag1)
{
ps=con.prepareStatement("insert into uin values(?)");
ps.setString(1,name);
int i=ps.executeUpdate();
if(i>0)
System.out.println("Number is Successfully Inserted");
}
else
System.out.println("Number is already inserted");
rs.close();
st.close();
ps.close();
con.close();
}//try
catch(Exception e)
{
e.printStackTrace();
}
}//test()
public static void main(String args[])
{
test t=new test();
String st="s7048223a";
t.test1(st);
}//main()
}//class
ERROR IN RUNTIME IS
----------------------
java.lang.NullPointerException
at test.test1(test.java:27)
at test.main(test.java:61)