This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds and have James Denton on-line!
See this thread for details.
Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Exception executing servlet with database connectivity  RSS feed

 
Greenhorn
Posts: 21
Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Author and ninkuma
Marshal
Posts: 66804
168
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moved to the JDBC forum.
 
Ranch Hand
Posts: 72
Eclipse IDE Hibernate Tomcat Server
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
 
Ranch Hand
Posts: 112
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 4
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 21
Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 21
Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 21
Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anyways , I thank you all for having helped me to execute my Very First Servlet program with Database Connectivity Successfully .



Thanks Again


Regards,
Kasiraj
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!