File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes Exception executing servlet with database connectivity Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Exception executing servlet with database connectivity" Watch "Exception executing servlet with database connectivity" New topic
Author

Exception executing servlet with database connectivity

Kasiraj Murugesa pandian
Greenhorn

Joined: Sep 09, 2011
Posts: 21

Hi,
Actually i just tried to do a Servlet program along with Database connectivity in which Name and Age is got from a Webpage and then after submitting the values the database had to be updated. This is what i was trying to do .

Although i could compile and build the file successfully using Netbeans with all those Try-catch block included in it , i ended up in getting a list of Exceptions soon after i clicked the Submit button.

So here are the Details of the Program:

Database Driver : Type 4 Driver [ Derby-client]
Web Application Server: Glassfish Server 3.1
Source Code :
NewServlet.java


And here are the List of Exceptions that i got soon after i clicked the Submit Button.

Exceptions

INFO: WEB0671: Loading application [WebApplication2] at [/WebApplication2]
INFO: WebApplication2 was successfully deployed in 508 milliseconds.
SEVERE: The log message is null.
java.sql.SQLException: At least one parameter to the current statement is uninitialized.
at org.apache.derby.client.am.SQLExceptionFactory40.getSQLException(Unknown Source)
at org.apache.derby.client.am.SqlException.getSQLException(Unknown Source)
at org.apache.derby.client.am.Statement.executeUpdate(Unknown Source)
at Com.NewServlet.processRequest(NewServlet.java:43)
at Com.NewServlet.doGet(NewServlet.java:71)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:734)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1539)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:98)
at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:91)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:162)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:330)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:174)
at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:828)
at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:725)
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1019)
at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:225)
at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
at java.lang.Thread.run(Thread.java:722)
Caused by: org.apache.derby.client.am.SqlException: At least one parameter to the current statement is uninitialized.
at org.apache.derby.client.am.Statement.completeSqlca(Unknown Source)
at org.apache.derby.client.am.Statement.completeExecuteImmediate(Unknown Source)
at org.apache.derby.client.net.NetStatementReply.parseEXCSQLIMMreply(Unknown Source)
at org.apache.derby.client.net.NetStatementReply.readExecuteImmediate(Unknown Source)
at org.apache.derby.client.net.StatementReply.readExecuteImmediate(Unknown Source)
at org.apache.derby.client.net.NetStatement.readExecuteImmediate_(Unknown Source)
at org.apache.derby.client.am.Statement.readExecuteImmediate(Unknown Source)
at org.apache.derby.client.am.Statement.flowExecute(Unknown Source)
at org.apache.derby.client.am.Statement.executeUpdateX(Unknown Source)
... 30 more



Hence It would be really nice of you , if you could help me execute my First Servlet program with Database Connectivity successfully .

Thanks in Advance .

Regards,
Kasiraj
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61610
    
  67

Moved to the JDBC forum.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Gopakumar Naryanan
Ranch Hand

Joined: Jan 15, 2011
Posts: 72


Connection con=DriverManager.getConnection("jdbc:derby://localhost:1527/UserData","kasi","kasi");
String str="insert into Nameage(Name,Age) Values(?,?)";

I think there might be some problem with your connestion string:

replace // with @ , / with : and try. I mean to say , it should look like below: (it might be one of the problems)

jdbc:derby:@localhost:1527:UserData","kasi","kasi"

Coming to Query:
You are not using PreparedStatement.. then why did you use '?' in the place of value you wanted to insert?

one simple advise try to print the status of all JDBC coding.. like "driver loaded" , "connection established" and "query status".. so that you can trace yourself where the exception occurs

try with these and let me know the status.

Thanks
Gopakumar


Thanks & Regards
Gopakumar
Pankaj Kumarkk
Ranch Hand

Joined: Apr 17, 2011
Posts: 108
I do not see any code which is passing the name and age values to the sql string. How is the Statement supposed to get the data which is to be inserted.
Harshal Mekhale
Greenhorn

Joined: Sep 17, 2011
Posts: 4
For accepting values from user use PreparedStatement and you need to set those values specifying the Parameter index and value pair for each.
Kasiraj Murugesa pandian
Greenhorn

Joined: Sep 09, 2011
Posts: 21

gopakumar kiing wrote:
Connection con=DriverManager.getConnection("jdbc:derby://localhost:1527/UserData","kasi","kasi");
String str="insert into Nameage(Name,Age) Values(?,?)";

I think there might be some problem with your connestion string:

replace // with @ , / with : and try. I mean to say , it should look like below: (it might be one of the problems)

jdbc:derby:@localhost:1527:UserData","kasi","kasi"

Coming to Query:
You are not using PreparedStatement.. then why did you use '?' in the place of value you wanted to insert?

one simple advise try to print the status of all JDBC coding.. like "driver loaded" , "connection established" and "query status".. so that you can trace yourself where the exception occurs

try with these and let me know the status.

Thanks
Gopakumar



Thanks a lot Gopal kumar the method of using Prepared Statement helped a lot and there was nothing wrong in running the program after using the PreparedStatement in it and later i got no issues with the database Connection . Here is what i did :

I replaced the code with the Following Statement :


Then i got it right .

Thanks Again !
Kasiraj Murugesa pandian
Greenhorn

Joined: Sep 09, 2011
Posts: 21

Harshal Mekhale wrote:For accepting values from user use PreparedStatement and you need to set those values specifying the Parameter index and value pair for each.


Yes Harshal, That was wat i exactly did and got it Right

Thank you for you Valuable and Meticulous Information about the preparedStatement


Regards,
Kasiraj
Kasiraj Murugesa pandian
Greenhorn

Joined: Sep 09, 2011
Posts: 21

Anyways , I thank you all for having helped me to execute my Very First Servlet program with Database Connectivity Successfully .



Thanks Again


Regards,
Kasiraj
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Exception executing servlet with database connectivity