Hi All,
I am trying to create new class in Eclipse and trying to insert a value in the DB from java.I am not able to fetch the the resultset .I have been working all these days. I can fetch and update in other tables.Whatever table I create today,I am not able to perform anything.Pl.help.The code is
as follows.
I get a NullPointer Exception
public synchronized boolean addClientInfo()
{
PreparedStatement pstmt= null;
ResultSet rst= null;
PreparedStatement ps= null;
ResultSet rs= null;
boolean status = false;
int max_clientid = 0;
try
{
pstmt = conn.prepareStatement("select CL_id from clientinfonew");
pstmt.executeQuery();
System.out.println("after execute");
//rst.next();
if( ((rst).equals(null)) || (rst == null))
{
System.out.println("IF PART");
max_clientid=0;
}
else
{
System.out.println("else part");
max_clientid = rst.getInt("CL_id");
}
status=true;
int maxcl = max_clientid+1;
System.out.println(maxcl);
pstmt.close();
return true;
}
catch(Exception e)
{
System.out.println(e);
}
finally
{
}
return false;
}
public static void main(
String[] args)
{
PoolManager poolMgr=PoolManager.getInstance();
Connection conn = poolMgr.getConnection("myconn");
System.out.println(conn);
com.fms.portal.ClientInfoNew clinfo = new com.fms.portal.ClientInfoNew();
clinfo.setConn(conn);
try
{
clinfo.setCL_id(0);
clinfo.setCL_fname("clientfname");
boolean add = clinfo.addClientInfo();
if(add)
{
System.out.println("added");
}
else
{
System.out.println("Not Added");
}
}
catch(Exception e)
{
System.out.println(e);
e.printStackTrace();
e.getMessage();
}
poolMgr.freeConnection("myconn", conn);
poolMgr.release();
}