• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Assistance with retrieving data from mysql DB

 
Samuel Bird
Ranch Hand
Posts: 96
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, this is my first post. I am having an issue working out why my servlet is not working to retrieve and display the records on my requested table. I am using Apache Tomcat App Server. I would appreciate any feedback on why it is not working.

The servlet:




The console when it occurs:

Jul 19, 2013 12:11:59 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [com.demotrial.servlet.Servtrial] in context with path [/Trialer] threw exception [Could not find data requested] with root cause
javax.servlet.ServletException: Could not find data requested
at com.demotrial.servlet.Servtrial.doGet(Servtrial.java:62)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:45)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:680)



 
J. Kevin Robbins
Bartender
Pie
Posts: 1801
28
Chrome Eclipse IDE Firefox Browser jQuery Linux MySQL Database Netbeans IDE
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I see a couple of potential problems.

On line 40, that space in "Amphibian Info" could be an issue.

On line 42, is your table really named "Servlet"?

On line 62, don't throw a new exception because you are losing information that way. Instead, do a "e.printStacktrace()" to see what the real error is.

Unrelated to your current problem, but on line 84 you should do a pr.flush() before doing a pr.close().
 
Richard Tookey
Bartender
Posts: 1166
17
Java Linux Netbeans IDE
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your use of
throws away the information about what went wrong. You should chain the exception using something like

then you will be able to see what went wrong.

It is normally a bad idea to put your JDBC code actually in the Servlet. It is better to delegate the operation to a Data Access Object (DAO) class that can easily be tested outside of the Servlet.

 
Samuel Bird
Ranch Hand
Posts: 96
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for all feedback so far. I have previously been told i should use DOA's and i will once i have just solved this, thankyou. I made all chanegs you suggested and this is the new console result:


SEVERE: Servlet.service() for servlet [com.demotrial.servlet.Servtrial] in context with path [/Trialer] threw exception [Could not find data requested] with root cause
java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:351)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:213)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:200)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:432)
at java.net.Socket.connect(Socket.java:529)
at java.net.Socket.connect(Socket.java:478)
at java.net.Socket.<init>(Socket.java:375)
at java.net.Socket.<init>(Socket.java:218)
at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:259)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:307)
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2479)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2516)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2301)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:834)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:416)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:346)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:207)
at com.demotrial.servlet.Servtrial.doGet(Servtrial.java:40)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:45)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:680)




any comment?
 
Samuel Bird
Ranch Hand
Posts: 96
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When i replaced the throws with e.printStackTrace();, it churned up this:


com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1121)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:357)
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2479)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2516)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2301)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:834)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:416)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:346)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:207)
at com.demotrial.servlet.Servtrial.doGet(Servtrial.java:40)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:45)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:680)
Caused by: java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:351)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:213)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:200)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:432)
at java.net.Socket.connect(Socket.java:529)
at java.net.Socket.connect(Socket.java:478)
at java.net.Socket.<init>(Socket.java:375)
at java.net.Socket.<init>(Socket.java:218)
at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:259)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:307)
... 34 more

is there something here? To me, it looks like the connection is not working?
 
J. Kevin Robbins
Bartender
Pie
Posts: 1801
28
Chrome Eclipse IDE Firefox Browser jQuery Linux MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's more helpful. You are exactly right; the connection is failing. That takes me back to that space in your connection string. It doesn't look right to me. I've never had to use a connection with a space in it so I don't know if that is valid, but I suspect it's not.

The other thing to check is to verify the port. Can you connect to the database using WinSQL or something similar?
 
Samuel Bird
Ranch Hand
Posts: 96
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you just reminded me. I recently had to change port or sql server. I will reconfigure ad get back to you.
 
Richard Tookey
Bartender
Posts: 1166
17
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Samuel Bird wrote: I have previously been told i should use DOA's and i will once i have just solved this


You will solve the problem much faster if you convert to using a DAO now. I know you won't believe me but ...

I too don't like the space in your connection URL ! You could try URL encoding it but I since I never create URL's containing a space I have no experience to indicate whether or not it will work.
 
Samuel Bird
Ranch Hand
Posts: 96
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmm...that didn't work. Do you know how I could either change database name in mysql or how i could allow for that in servlet i.e. surround in square brackets?
 
Samuel Bird
Ranch Hand
Posts: 96
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you know where i could learn how to use the DAO's?
 
Richard Tookey
Bartender
Posts: 1166
17
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Samuel Bird wrote:Do you know how I could either change database name in mysql


Google

or how i could allow for that in servlet i.e. surround in square brackets?


Did you try URL encoding it as I suggested as a possibility ?
 
Richard Tookey
Bartender
Posts: 1166
17
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Samuel Bird wrote:Do you know where i could learn how to use the DAO's?


Google
 
Samuel Bird
Ranch Hand
Posts: 96
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have created a DAO to cretae the connection. How would i then access this connection from my servlet?

My DAO:



 
Samuel Bird
Ranch Hand
Posts: 96
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I assume i just create an object?
 
Samuel Bird
Ranch Hand
Posts: 96
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How would i then call upon the connection to create a statement?
 
Samuel Bird
Ranch Hand
Posts: 96
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried dao(the object).makecon(the connection making method) but it says the method is not defined for DAO.
 
Richard Tookey
Bartender
Posts: 1166
17
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Google is your friend - found in the first 5 results of a simple Google search http://javarevisited.blogspot.co.uk/2013/01/data-access-object-dao-design-pattern-java-tutorial-example.html .

Did you use Google to find out how to change a table name? Trivial.
 
Samuel Bird
Ranch Hand
Posts: 96
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can change table name just not DB name.
 
J. Kevin Robbins
Bartender
Pie
Posts: 1801
28
Chrome Eclipse IDE Firefox Browser jQuery Linux MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Samuel Bird wrote:Hmm...that didn't work. Do you know how I could either change database name in mysql or how i could allow for that in servlet i.e. surround in square brackets?


All the work I've done with mySQL involved using phpMyAdmin. It's invaluable for working with mySQL. I'm sure you can easily rename the database using that tool. I wouldn't know off the top of my head how to do it using the command line tools.
 
J. Kevin Robbins
Bartender
Pie
Posts: 1801
28
Chrome Eclipse IDE Firefox Browser jQuery Linux MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Samuel Bird wrote:I tried dao(the object).makecon(the connection making method) but it says the method is not defined for DAO.


This is a little puzzling. Post the servlet code where you are creating the DAO and invoking the makecon method.
 
Samuel Bird
Ranch Hand
Posts: 96
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ive now tried something different and am creating all the methods inside the DAO:





but there is an error when i try to create the print writer as it says "response" cant be resolved.


Update:

I have now installed the necessary packages but there was still an issue with recognising the CS so i made the new method get info, inside DAO, implement the makecon method. However, it is now saying i must throw something What is it? I tried SQLNotFoundException and ClassNotFoundException.
 
Samuel Bird
Ranch Hand
Posts: 96
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are also errors on line 31 and 94 for the parameters. Why are there errors?
 
Amit Ghorpade
Bartender
Posts: 2854
10
Fedora Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Samuel Bird wrote:

This is a DAO class and not the servlet where you had the above line. So there is no declaration for the response object here.
Also you cannot print anything to the response from a DAO class. You need to pass the data to the servlet for printing.
 
Amit Ghorpade
Bartender
Posts: 2854
10
Fedora Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hint: for most of the errors, I think there is something wrong on line number 35 above.
 
J. Kevin Robbins
Bartender
Pie
Posts: 1801
28
Chrome Eclipse IDE Firefox Browser jQuery Linux MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just to expand a bit on Amits reponse, the DAO is a Plain Old Java Object. It doesn't know anything about request or response objects; those are http specific so only the servlet understands them. The DAO will need to put the data into something and pass it back to the servlet. That "something" is usually a JavaBean or a collection such as a Map or List, or even a collection of JavaBeans. It depends on the requirements of the application.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65335
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And... just in case you get the urge to pass the request or response info into the DAO so it can use them, don't. That would be an egregious violation of Separation of Concerns. And that way lies madness.
 
Samuel Bird
Ranch Hand
Posts: 96
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have another issue now. All of the code is in the DAO and the servlet calls it and there are no errors but now when i run it i get this error:

NAME LIFESPAN SIZE HABITAT DIET ORIGIN ENVIRONMENTAL SAFETY CODE
-------------------- -- -- ------------------ -------------- ----------------- -- --
Jul 22, 2013 10:34:46 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [com.demotrial.servlet.Servtrial] in context with path [/Trialer] threw exception
java.util.IllegalFormatConversionException: d != java.lang.String
at java.util.Formatter$FormatSpecifier.failConversion(Formatter.java:3999)
at java.util.Formatter$FormatSpecifier.printInteger(Formatter.java:2709)
at java.util.Formatter$FormatSpecifier.print(Formatter.java:2661)
at java.util.Formatter.format(Formatter.java:2433)
at java.io.PrintStream.format(PrintStream.java:920)
at com.demotrial.servlet.DAO.getinfo(DAO.java:66)
at com.demotrial.servlet.Servtrial.doGet(Servtrial.java:29)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:45)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:680)


Firstly, I do not know what these errors mean and what has gone wrong. Secondly, the formatting on the part that did render looks wrong and iwas a bit confused with the formatting:



I was not sure what to do with the %' and so on. A response would be useful, Sam.
 
Richard Tookey
Bartender
Posts: 1166
17
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Taken with your earlier posts, your statement "I was not sure what to do with the %' and so on." seems to indicate a reluctance to read documentation and a reliance on copying code from other people. The Javadoc for String.format() points you to the Formatter class and you could save yourself a lot of time by taking the time to read the Javadoc.

As a hint - what do you think the "%n" at the end of your formatting string is supposed to do because it won't give you a new line!

 
Samuel Bird
Ranch Hand
Posts: 96
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, I am just looking at the docs now for the JDBC. Ill check that out now.
 
Samuel Bird
Ranch Hand
Posts: 96
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the java api docs, where should i be looking. What class contains these formatting rules?
 
Samuel Bird
Ranch Hand
Posts: 96
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok , i just couldn't see the formatter class before. I see it now.
 
Samuel Bird
Ranch Hand
Posts: 96
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, I have fixed the formatting but I really am stuck on the error code. Can you just tell me what it is that is wrong please so i can find out how to fix it, Sam.
 
J. Kevin Robbins
Bartender
Pie
Posts: 1801
28
Chrome Eclipse IDE Firefox Browser jQuery Linux MySQL Database Netbeans IDE
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Samuel Bird wrote:
at java.io.PrintStream.format(PrintStream.java:920)
at com.demotrial.servlet.DAO.getinfo(DAO.java:66)


These lines are your hint. The second one is is the last operation attempted by your code before it blew up when it called PrintStream.format, so look at line 66 of your DAO. What are you trying to format?

I would put a breakpoint a couple of lines prior to that point and run it in debug mode. See what value you are passing to the format method and ask yourself if it's valid.
 
Richard Tookey
Bartender
Posts: 1166
17
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Samuel Bird wrote:Ok, I have fixed the formatting but I really am stuck on the error code. Can you just tell me what it is that is wrong please so i can find out how to fix it, Sam.


I might be able to help with the error code if you indicated what it was !!! Do you mean the exception? If so then the previous poster indicates one way to find the problem.
 
Samuel Bird
Ranch Hand
Posts: 96
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is the area of line 66 and line 66 is the formatting part:

 
Samuel Bird
Ranch Hand
Posts: 96
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I ran it in debug mode and it just said i needed to debug this:



I just don't know what is wrong with it.
 
Samuel Bird
Ranch Hand
Posts: 96
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This time I removed the ResultSet rs = null; and intitialized it when i was using the st.executeQuery and this removed the bug but now another one appeared when i create the statement before it. See here:

 
Samuel Bird
Ranch Hand
Posts: 96
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Even though the bug is no longer appearing, Ive still noticed the code has error causes at the formatting line mentioned earlier (line 66). Could this be because of the statemnt bug?
 
Richard Tookey
Bartender
Posts: 1166
17
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Samuel Bird wrote:Even though the bug is no longer appearing, Ive still noticed the code has error causes at the formatting line mentioned earlier (line 66). Could this be because of the statemnt bug?


Why are you still running this in a Servlet? The DAO should be tested outside of the Servlet in a simple test harness.

You have two parts in your DAO . You have an SQL query and some formatting. Running the DAO outside of the Servlet you should be able to check that the results set values are as you would expect. When you are happy with that you should then deal with the formatting problems. I can see one obvious bug in the formatting but there may be more.

Trying to debug an amorphous blob of code is difficult and one should separate out the parts into testable parts. This is a primary reason to create a simple stand alone test harness outside of the Servlet.
 
Samuel Bird
Ranch Hand
Posts: 96
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok ill do that now.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic