• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java.lang.NullPointerException

 
jaya kemmannu
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi,

I am facing java.lang.NullPointerException in the below code. The code reads data from input files and process them line by line. But when the second line is processed i get NullPointerException.

Exception :

java.lang.NullPointerException
at com.hp.np.sca.UpdateSDA.getTXNID(UpdateSDA.java:100)
at com.hp.np.sca.UpdateSDA.main(UpdateSDA.java:64)


Code



Regards,
Jay
 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That stack trace tells you exactly which line the exception is happening on. Unfortunately the line numbers don't match the code you've posted. So can you tell us which line corresponds to line 100 of UpdateSDA.java?
 
K. Gil
Ranch Hand
Posts: 75
Java Linux Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That stack trace tells you exactly which line the exception is happening on. Unfortunately the line numbers don't match the code you've posted. So can you tell us which line corresponds to line 100 of UpdateSDA.java?


That's the easy bit

java.lang.NullPointerException
at com.hp.np.sca.UpdateSDA.getTXNID(UpdateSDA.java:100)

so going through code...

public class UpdateSDA {
static Connection vConn = null;
public static void main(String[] args) throws IOException {
BufferedReader br = null;
try {
br = new BufferedReader(new FileReader("/apps/SDA.csv"));
vConn = UpdateSDA.getConnection();
vConn.setAutoCommit(false);
while ((str = br.readLine()) != null && str.length()!=0) {
System.out.println("update np main schema");
String npTxnId = getTXNID(portid,vConn);


then getTXNID which expecting 2 parameters, PortID and con:

private static String getTXNID(String portID,Connection con) {
//Connection vcon = null;
PreparedStatement vstmt = null;
ResultSet vRes = null;
String TXNID = null;
try {
con = UpdateSDA.getConnection();
System.out.println("SQL Select Query :" + SQL_SELECT_NP_TXN_ID);
vstmt = con.prepareStatement(SQL_SELECT_NP_TXN_ID);
vstmt.setString(1, portID);
vRes = vstmt.executeQuery();
while(vRes != null && vRes.next()) {
TXNID = vRes.getString("NP_TXN_ID");
System.out.println("TXN ID obtained : "+TXNID);
}
}
catch (SQLException e) {
e.printStackTrace();
}
finally {
try {
if(vRes != null) {
vRes.close();
}
if(vstmt != null) {
vstmt.close();
}
} catch (SQLException e)
{
e.printStackTrace();
}
}
return TXNID;
}


vConn which is passed as connection looks okay, as it comes from UpdateSDA.getConnection(); and based on that function, if connection would be not possible you would get:
System.out.println("Connection cannot be established");
so I bet on invalid portid in this case, because I can't really find what that one comes from.
if the reason for this csv file is to keep this information, then probably...
while ((str = br.readLine()) != null && str.length()!=0) { // should be updated from str to portid or
String npTxnId = getTXNID(portid,vConn); //// portid replaced with str
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic