This week's book giveaway is in the General Computing forum. We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line! See this thread for details.
I am writing a batch program and I have Prepared Statement class where I would like to prepare all the queries before I start processing the files. But the problem is When I try to execute the Prepared statement, it becomes null . For example it is null in getData(String value) method of below code snippet.
Thanks Maria
[edited to add code tags] [ February 03, 2005: Message edited by: Jeanne Boyarsky ]
If you are getting sql exception then its relating to sql statement in query. If the query is update then check for all columns values in sql statement. I mean for not null values there has to be some values and in case of select statement whether the column names are correct in relation to column name in table.
Maria Smith
Ranch Hand
Joined: Apr 01, 2004
Posts: 40
posted
0
I am sorry I am getting java.lang.NullPointerException. And I am sure there is no problem with prepared statement. Because if I exceute Prepare statement in the constructor itself I don't get any error message. But if I try to excute statement later after some processing is done, as I metioned aboe I get null pointer exception.
Damanjit Kaur
Ranch Hand
Joined: Oct 18, 2004
Posts: 346
posted
0
Ok then the problem might be in order of calling PrepareQuery() and getData().
Maria Smith
Ranch Hand
Joined: Apr 01, 2004
Posts: 40
posted
0
Thank you for your help I changed my class a bit. I am preparing statements in a method instead of a costructor I call the method Test() from my driver class to prepare the Statment. and I am calling getData(String value) method later from different program.
Do you know how can i hold the connection after preparing the statement. Because for some reason connection becomes null and it is causing the problem
[edited to add code tags] [ February 03, 2005: Message edited by: Jeanne Boyarsky ]
Maria, The connection object should not be null (unless you are assigning null to it somewhere.) Try searching the full code for "connection =".
Also, I added UBB code tags to your posts. It makes code easier to read. For future reference, the UBB tags are right below the editor on the edit screen.
Where have you declared conn variable. I suppose its declared as class variable. Then better way would be to instantiate it in constructor and not close it in other methods. or open and close it in each method which have to use the Connection but that way would be better in case of connection pooling.