Hello friends,
I want to retrive data from my database through SQL but Iam facing a probem with my code, a runtime error Named "Null Pointer Exception occured" while retrieving data from database, using resultset,
the snapshot of my code is as follows:----
String str = null;
PreparedStatement pstmt = null;
Statement stat = null;
ResultSet result = null;
Connection con = null;
String name = null;
String dat = null;
String mont = null;
String year = null;
try
{
str="SELECT * FROM date_of_birth WHERE id = ?";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:myData","sa","12345678");
stat = con.createStatement();
pstmt.setInt(1,1);
pstmt = con.prepareStatement(str);
result = pstmt.executeQuery();
while(result.next())
{
name = result.getString("nam");
dat = result.getNString("dat");
mont = result.getNString("mont");
year = result.getString("yer");
}
jLabel2.setText(name);
jLabel4.setText(dat);
jLabel6.setText(mont);
jLabel8.setText(year);
stat.close();
pstmt.close();
result.close();
con.close();
}
catch(Exception e)
{
System.out.println("Error Occurred "+e.toString());
}
initComponents();
}
In this code I got null pointer runtime exception, when I use resultset querry......
So, it would be kind enough for me to solve this problem, Iam using Windows XP Service Pack 2 and SQL Server 2005 Developer Edition Database