mwari
asked on
getting error java.sql.SQLException No available resource. Wait-time expired. when trying to save into db.
I am getting the following exception when I try to save info into a db.
Basically what happens is I save information from a csv file into a csvfile table, if the operation is succesfull then I retrieve the information from csvfile table and save it to daceaccount table, thereafter to get the total I read the daceaccount table and load the Reference number and the total, It takes about a long time to execute about 4mins and when it does, it does not save anything. When I look in the logs I see the exception:
java.sql.SQLException No available resource. Wait-time expired
This is done inside a servlet here is the code snippet of the code that does this:
protected void processRequest(HttpServlet Request request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("t ext/html") ;
PrintWriter out = response.getWriter();
CsvDateUtil csvdate= new CsvDateUtil();
out.println("<input type=hidden name=proc value=proc>");
/* checking if file saved file exists, if so read the
file using CSVFileReader process method, which will
read the file and write it to the database.*/
today= Calendar.getInstance();
if(request.getParameter("f iles")!=nu ll){
if(request.getParameter("f iles").end sWith(".cs v")){
try{
con= c.getJndiConnection();
pstmt = con.createStatement();
csv.setCSVDirectory(reques t.getParam eter("path tocsv"));
csv.setSkippedRows(3);
List two= csv.getResults(2, request.getParameter("csvf ilename"). replaceAll (".csv", ""));
List four= csv.getResults(4, request.getParameter("csvf ilename"). replaceAll (".csv", ""));
List five= csv.getResults(5, request.getParameter("csvf ilename"). replaceAll (".csv", ""));
List six= csv.getResults(6, request.getParameter("csvf ilename"). replaceAll (".csv", ""));
PropertyReader reader =new PropertyReader();
for (int i=0; i < two.size(); i++){
String insvalues="insert into csvfile values ('"+new CsvDateUtil().date(two, i, "")+"', '"+four.get(i)+"', '"+five.get(i)+"', '"+six.get(i).toString().t rim()+"')" ;
chk= pstmt.executeUpdate(insval ues);
System.out.println("---sta tus of insert csvfile table "+chk);
}
if(chk > 0){
m = pstmt.executeUpdate("inser t into daceaccount select Dates, Amount, Transaction, Reference from csvfile WHERE NOT EXISTS (SELECT daceaccount.Dates, daceaccount.Amount, daceaccount.Transaction, daceaccount.Reference from daceaccount where daceaccount.Reference = csvfile.Reference and daceaccount.Dates = csvfile.Dates and csvfile.Amount = daceaccount.Amount)");
if(m > 0 ){
try{
k= pstmt.executeUpdate("delet e from total");
k= pstmt.executeUpdate(" insert into total select Reference, sum(Amount) from daceaccount group by Reference");
if(k > 0){
System.out.println("---Suc cessfully inserted "+k+" rows in total");
}
}catch(Exception e){
e.printStackTrace();
}
System.out.println("--Succ essfully modified " + m + " rows.\n");
}else{
System.out.println("---(Cl ass Test), No updates required");
}
}else{
System.out.println("unable to save info to csvfile table");
}
} catch (SQLException se) {
System.out.println("We got an exception while executing our query:" +
"that probably means our SQL is invalid");
se.printStackTrace();
System.exit(1);
} finally {
try { pstmt.close(); } catch(SQLException e) { e.printStackTrace(); }
try { con.close(); } catch(SQLException e) { e.printStackTrace(); }
}
}else if(!request.getParameter(" files").en dsWith(".c sv")){
out.println("<center><font color=red size=2 face=Tahoma>Wrong file type (must be csv file)</font></center>");
}
}
if(request.getAttribute("f ilename")! =null){
out.println("<html>");
out.println("<body>");
out.println("<center><P>&n bsp;</P>") ;
out.println("<P><FONT face=Tahoma size=2>The following file has been saved to directory<FONT color=#0000ff> /tmp</FONT> click continue to proceed.</FONT></P>");
out.println("<FORM METHOD=POST ACTION=/accounting/servlet /utilities .Intercept orServlet> ");
out.println("<input type=hidden name=uploads value=uploads>");
out.println("<P><FONT face=Tahoma size=2></FONT><INPUT TYPE=text NAME=files value='"+request.getAttrib ute("filep ath")+"/"+ request.ge tAttribute ("filename ")+"'><INP UT type=submit value=continue name=continue></P>");
out.println("<input type=hidden name=pathtocsv value='"+request.getAttrib ute("filep ath")+"'>" );
out.println("<input type=hidden name=csvfilename value='"+request.getAttrib ute("filen ame")+"'>" );
out.println("</FORM>");
out.println("<P> </P> </center>" );
out.println("</body>");
out.println("</html>");
}
out.close();
}
Basically what happens is I save information from a csv file into a csvfile table, if the operation is succesfull then I retrieve the information from csvfile table and save it to daceaccount table, thereafter to get the total I read the daceaccount table and load the Reference number and the total, It takes about a long time to execute about 4mins and when it does, it does not save anything. When I look in the logs I see the exception:
java.sql.SQLException No available resource. Wait-time expired
This is done inside a servlet here is the code snippet of the code that does this:
protected void processRequest(HttpServlet
throws ServletException, IOException {
response.setContentType("t
PrintWriter out = response.getWriter();
CsvDateUtil csvdate= new CsvDateUtil();
out.println("<input type=hidden name=proc value=proc>");
/* checking if file saved file exists, if so read the
file using CSVFileReader process method, which will
read the file and write it to the database.*/
today= Calendar.getInstance();
if(request.getParameter("f
if(request.getParameter("f
try{
con= c.getJndiConnection();
pstmt = con.createStatement();
csv.setCSVDirectory(reques
csv.setSkippedRows(3);
List two= csv.getResults(2, request.getParameter("csvf
List four= csv.getResults(4, request.getParameter("csvf
List five= csv.getResults(5, request.getParameter("csvf
List six= csv.getResults(6, request.getParameter("csvf
PropertyReader reader =new PropertyReader();
for (int i=0; i < two.size(); i++){
String insvalues="insert into csvfile values ('"+new CsvDateUtil().date(two, i, "")+"', '"+four.get(i)+"', '"+five.get(i)+"', '"+six.get(i).toString().t
chk= pstmt.executeUpdate(insval
System.out.println("---sta
}
if(chk > 0){
m = pstmt.executeUpdate("inser
if(m > 0 ){
try{
k= pstmt.executeUpdate("delet
k= pstmt.executeUpdate(" insert into total select Reference, sum(Amount) from daceaccount group by Reference");
if(k > 0){
System.out.println("---Suc
}
}catch(Exception e){
e.printStackTrace();
}
System.out.println("--Succ
}else{
System.out.println("---(Cl
}
}else{
System.out.println("unable
}
} catch (SQLException se) {
System.out.println("We got an exception while executing our query:" +
"that probably means our SQL is invalid");
se.printStackTrace();
System.exit(1);
} finally {
try { pstmt.close(); } catch(SQLException e) { e.printStackTrace(); }
try { con.close(); } catch(SQLException e) { e.printStackTrace(); }
}
}else if(!request.getParameter("
out.println("<center><font
}
}
if(request.getAttribute("f
out.println("<html>");
out.println("<body>");
out.println("<center><P>&n
out.println("<P><FONT face=Tahoma size=2>The following file has been saved to directory<FONT color=#0000ff> /tmp</FONT> click continue to proceed.</FONT></P>");
out.println("<FORM METHOD=POST ACTION=/accounting/servlet
out.println("<input type=hidden name=uploads value=uploads>");
out.println("<P><FONT face=Tahoma size=2></FONT><INPUT TYPE=text NAME=files value='"+request.getAttrib
out.println("<input type=hidden name=pathtocsv value='"+request.getAttrib
out.println("<input type=hidden name=csvfilename value='"+request.getAttrib
out.println("</FORM>");
out.println("<P> </P>
out.println("</body>");
out.println("</html>");
}
out.close();
}
What other output are you getting - of your own debug statements i mean?
ASKER
no other debugging information of mine is printed.
Go back then. Put something before and after this:
>>con= c.getJndiConnection();
>>con= c.getJndiConnection();
ASKER
I have done that and I even went on to use a lookup from my servlet as follows. I get the following error.
CORE3282: stdout: ---proc4---
[21/Aug/2005:15:54:21] SEVERE (12005): ApplicationDispatcher[/acc ounting] Servlet.service() for servlet CVSProcessServlet threw exception
java.lang.NullPointerExcep tion
at com.alindigo.costrecovery. jdbcUtilit ies.CSVPro cessServle t.processR equest(CSV ProcessSer vlet.java: 237)
at com.alindigo.costrecovery. jdbcUtilit ies.CSVPro cessServle t.doPost(C SVProcessS ervlet.jav a:279)
at javax.servlet.http.HttpSer vlet.servi ce(HttpSer vlet.java: 760)
here is the changed code:
protected void processRequest(HttpServlet Request request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("t ext/html") ;
PrintWriter out = response.getWriter();
CsvDateUtil csvdate= new CsvDateUtil();
out.println("<input type=hidden name=proc value=proc>");
/* checking if file saved file exists, if so read the
file using CSVFileReader process method, which will
read the file and write it to the database.*/
try{
ic = new InitialContext();
ds = (DataSource)ic.lookup("jdb c/GDACEapp lications" );
con = ds.getConnection();
}catch(Exception e){
e.printStackTrace();
}
System.out.println("---pro c1---");
today= Calendar.getInstance();
System.out.println("---pro c2---");
if(request.getParameter("f iles")!=nu ll){
System.out.println("---pro c3---");
if(request.getParameter("f iles").end sWith(".cs v")){
try{
System.out.println("---pro c4---");
con= c.getJndiConnection();
System.out.println("---pro c5---");
pstmt = con.createStatement();
System.out.println("---pro c6---");
csv.setCSVDirectory(reques t.getParam eter("path tocsv"));
System.out.println("---pro c7---");
csv.setSkippedRows(3);
System.out.println("---pro c8---");
List two= csv.getResults(2, request.getParameter("csvf ilename"). replaceAll (".csv", ""));
List four= csv.getResults(4, request.getParameter("csvf ilename"). replaceAll (".csv", ""));
List five= csv.getResults(5, request.getParameter("csvf ilename"). replaceAll (".csv", ""));
List six= csv.getResults(6, request.getParameter("csvf ilename"). replaceAll (".csv", ""));
PropertyReader reader =new PropertyReader();
System.out.println("---pro c7---");
for (int i=0; i < two.size(); i++){
System.out.println("---pro c8---");
String insvalues="insert into csvfile values ('"+new CsvDateUtil().date(two, i, "")+"', '"+four.get(i)+"', '"+five.get(i)+"', '"+six.get(i).toString().t rim()+"')" ;
chk= pstmt.executeUpdate(insval ues);
System.out.println("---sta tus of insert csvfile table "+chk);
}
if(chk > 0){
System.out.println("---pro c9---");
m = pstmt.executeUpdate("inser t into daceaccount select Dates, Amount, Transaction, Reference from csvfile WHERE NOT EXISTS (SELECT daceaccount.Dates, daceaccount.Amount, daceaccount.Transaction, daceaccount.Reference from daceaccount where daceaccount.Reference = csvfile.Reference and daceaccount.Dates = csvfile.Dates and csvfile.Amount = daceaccount.Amount)");
if(m > 0 ){
System.out.println("---pro c10---");
try{
System.out.println("---pro c11---");
k= pstmt.executeUpdate("delet e from total");
k= pstmt.executeUpdate(" insert into total select Reference, sum(Amount) from daceaccount group by Reference");
if(k > 0){
System.out.println("---Suc cessfully inserted "+k+" rows in total");
}
}catch(Exception e){
e.printStackTrace();
}
System.out.println("--Succ essfully modified " + m + " rows.\n");
}else{
System.out.println("---(Cl ass Test), No updates required");
}
}else{
System.out.println("unable to save info to csvfile table");
}
} catch (SQLException se) {
System.out.println("We got an exception while executing our query:" +
"that probably means our SQL is invalid");
se.printStackTrace();
System.exit(1);
} finally {
try { pstmt.close(); } catch(SQLException e) { e.printStackTrace(); }
try { con.close(); } catch(SQLException e) { e.printStackTrace(); }
}
}else if(!request.getParameter(" files").en dsWith(".c sv")){
out.println("<center><font color=red size=2 face=Tahoma>Wrong file type (must be csv file)</font></center>");
}
}
if(request.getAttribute("f ilename")! =null){
out.println("<html>");
out.println("<body>");
out.println("<center><P>&n bsp;</P>") ;
out.println("<P><FONT face=Tahoma size=2>The following file has been saved to directory<FONT color=#0000ff> /tmp</FONT> click continue to proceed.</FONT></P>");
out.println("<FORM METHOD=POST ACTION=/accounting/servlet /utilities .Intercept orServlet> ");
out.println("<input type=hidden name=uploads value=uploads>");
out.println("<P><FONT face=Tahoma size=2></FONT><INPUT TYPE=text NAME=files value='"+request.getAttrib ute("filep ath")+"/"+ request.ge tAttribute ("filename ")+"'><INP UT type=submit value=continue name=continue></P>");
out.println("<input type=hidden name=pathtocsv value='"+request.getAttrib ute("filep ath")+"'>" );
out.println("<input type=hidden name=csvfilename value='"+request.getAttrib ute("filen ame")+"'>" );
out.println("</FORM>");
out.println("<P> </P> </center>" );
out.println("</body>");
out.println("</html>");
}
out.close();
}
CORE3282: stdout: ---proc4---
[21/Aug/2005:15:54:21] SEVERE (12005): ApplicationDispatcher[/acc
java.lang.NullPointerExcep
at com.alindigo.costrecovery.
at com.alindigo.costrecovery.
at javax.servlet.http.HttpSer
here is the changed code:
protected void processRequest(HttpServlet
throws ServletException, IOException {
response.setContentType("t
PrintWriter out = response.getWriter();
CsvDateUtil csvdate= new CsvDateUtil();
out.println("<input type=hidden name=proc value=proc>");
/* checking if file saved file exists, if so read the
file using CSVFileReader process method, which will
read the file and write it to the database.*/
try{
ic = new InitialContext();
ds = (DataSource)ic.lookup("jdb
con = ds.getConnection();
}catch(Exception e){
e.printStackTrace();
}
System.out.println("---pro
today= Calendar.getInstance();
System.out.println("---pro
if(request.getParameter("f
System.out.println("---pro
if(request.getParameter("f
try{
System.out.println("---pro
con= c.getJndiConnection();
System.out.println("---pro
pstmt = con.createStatement();
System.out.println("---pro
csv.setCSVDirectory(reques
System.out.println("---pro
csv.setSkippedRows(3);
System.out.println("---pro
List two= csv.getResults(2, request.getParameter("csvf
List four= csv.getResults(4, request.getParameter("csvf
List five= csv.getResults(5, request.getParameter("csvf
List six= csv.getResults(6, request.getParameter("csvf
PropertyReader reader =new PropertyReader();
System.out.println("---pro
for (int i=0; i < two.size(); i++){
System.out.println("---pro
String insvalues="insert into csvfile values ('"+new CsvDateUtil().date(two, i, "")+"', '"+four.get(i)+"', '"+five.get(i)+"', '"+six.get(i).toString().t
chk= pstmt.executeUpdate(insval
System.out.println("---sta
}
if(chk > 0){
System.out.println("---pro
m = pstmt.executeUpdate("inser
if(m > 0 ){
System.out.println("---pro
try{
System.out.println("---pro
k= pstmt.executeUpdate("delet
k= pstmt.executeUpdate(" insert into total select Reference, sum(Amount) from daceaccount group by Reference");
if(k > 0){
System.out.println("---Suc
}
}catch(Exception e){
e.printStackTrace();
}
System.out.println("--Succ
}else{
System.out.println("---(Cl
}
}else{
System.out.println("unable
}
} catch (SQLException se) {
System.out.println("We got an exception while executing our query:" +
"that probably means our SQL is invalid");
se.printStackTrace();
System.exit(1);
} finally {
try { pstmt.close(); } catch(SQLException e) { e.printStackTrace(); }
try { con.close(); } catch(SQLException e) { e.printStackTrace(); }
}
}else if(!request.getParameter("
out.println("<center><font
}
}
if(request.getAttribute("f
out.println("<html>");
out.println("<body>");
out.println("<center><P>&n
out.println("<P><FONT face=Tahoma size=2>The following file has been saved to directory<FONT color=#0000ff> /tmp</FONT> click continue to proceed.</FONT></P>");
out.println("<FORM METHOD=POST ACTION=/accounting/servlet
out.println("<input type=hidden name=uploads value=uploads>");
out.println("<P><FONT face=Tahoma size=2></FONT><INPUT TYPE=text NAME=files value='"+request.getAttrib
out.println("<input type=hidden name=pathtocsv value='"+request.getAttrib
out.println("<input type=hidden name=csvfilename value='"+request.getAttrib
out.println("</FORM>");
out.println("<P> </P>
out.println("</body>");
out.println("</html>");
}
out.close();
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
you have just nailed the problem c refers my JNDIConnectionBean, it looks like I would have to rethink this class..
After removing it and doing a Direct lookup it now works well, Thanks you ;-)
After removing it and doing a Direct lookup it now works well, Thanks you ;-)
:-)