•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the JSP section within the Web Development category of DaniWeb, a massive community of 375,170 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,200 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JSP advertiser: Lunarpages JSP Web Hosting
Views: 4494 | Replies: 13
![]() |
•
•
Join Date: Mar 2007
Posts: 7
Reputation:
Rep Power: 0
Solved Threads: 1
Hi ! I have a problem in connecting JSP pages with My SQL database using JDBC connector. I m using:
JSP pages other than database working fine. I have copied mysql-connector-java-3.0.17-ga-bin.jar file in apache-tomcat-5.5.23\Tomcat 5.5\common\lib folder also for it. It is giving me error on connection line.
My Database structure is : Database: register, table: login, fields are: name, password, message.
I don’t know whether it’s a problem with compatibilities of different applications or there is something wrong with the code. Here is the code:
<%@ page import="java.sql.*" %>
<html><body>
<%
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:8009/login? user=root&password=asma");
Statement statement = con.createStatement();
ResultSet rs = statement.executeQuery("SELECT message FROM users");
while (rs.next()) {
out.println(rs.getString("message")+"<br>");
}
rs.close();statement.close();con.close();
%>
</body></html>
If anyone can help me I’ll be really greateful
And the error is :
HTTP Status 500 -
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: Exception in JSP: /connect1.jsp:63: 4: <%5: Class.forName("com.mysql.jdbc.Driver").newInstance();6: Connection con = DriverManager.getConnection("jdbc:mysql://localhost:8009/login? user=root&password=asma");7: Statement statement = con.createStatement();8: ResultSet rs = statement.executeQuery("SELECT message FROM users");9: Stacktrace: org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:467) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:371) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:315) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265) javax.servlet.http.HttpServlet.service(HttpServlet.java:803)root cause
javax.servlet.ServletException: Communication link failure: java.io.EOFException, underlying cause: null** BEGIN NESTED EXCEPTION ** java.io.EOFExceptionSTACKTRACE:java.io.EOFException at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:1395) at com.mysql.jdbc.MysqlIO.readPacket(MysqlIO.java:1414) at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:625) at com.mysql.jdbc.Connection.createNewIO(Connection.java:1808) at com.mysql.jdbc.Connection.<init>(Connection.java:452) at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:411) at java.sql.DriverManager.getConnection(Unknown Source) at java.sql.DriverManager.getConnection(Unknown Source) at org.apache.jsp.connect1_jsp._jspService(connect1_jsp.java:48) at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98) at javax.servlet.http.HttpServlet.service(HttpServlet.java:803) at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:328) at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:315) at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265) at javax.servlet.http.HttpServlet.service(HttpServlet.java:803) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:210) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:870) at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665) at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528) at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81) at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:685) at java.lang.Thread.run(Unknown Source)** END NESTED EXCEPTION ** org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:846) org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:779) org.apache.jsp.connect1_jsp._jspService(connect1_jsp.java:67) org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98) javax.servlet.http.HttpServlet.service(HttpServlet.java:803) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:328) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:315) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265) javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
- For TOMCAT -- apache-tomcat-5.5.23
- For JRE -- Java EE 5 SDK
- For database -- MySQL 5.0.37
- For JDBC -- mysql-connector-java-3.0.17
JSP pages other than database working fine. I have copied mysql-connector-java-3.0.17-ga-bin.jar file in apache-tomcat-5.5.23\Tomcat 5.5\common\lib folder also for it. It is giving me error on connection line.
My Database structure is : Database: register, table: login, fields are: name, password, message.
I don’t know whether it’s a problem with compatibilities of different applications or there is something wrong with the code. Here is the code:
<%@ page import="java.sql.*" %>
<html><body>
<%
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:8009/login? user=root&password=asma");
Statement statement = con.createStatement();
ResultSet rs = statement.executeQuery("SELECT message FROM users");
while (rs.next()) {
out.println(rs.getString("message")+"<br>");
}
rs.close();statement.close();con.close();
%>
</body></html>
If anyone can help me I’ll be really greateful
And the error is :
HTTP Status 500 -
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: Exception in JSP: /connect1.jsp:63: 4: <%5: Class.forName("com.mysql.jdbc.Driver").newInstance();6: Connection con = DriverManager.getConnection("jdbc:mysql://localhost:8009/login? user=root&password=asma");7: Statement statement = con.createStatement();8: ResultSet rs = statement.executeQuery("SELECT message FROM users");9: Stacktrace: org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:467) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:371) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:315) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265) javax.servlet.http.HttpServlet.service(HttpServlet.java:803)root cause
javax.servlet.ServletException: Communication link failure: java.io.EOFException, underlying cause: null** BEGIN NESTED EXCEPTION ** java.io.EOFExceptionSTACKTRACE:java.io.EOFException at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:1395) at com.mysql.jdbc.MysqlIO.readPacket(MysqlIO.java:1414) at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:625) at com.mysql.jdbc.Connection.createNewIO(Connection.java:1808) at com.mysql.jdbc.Connection.<init>(Connection.java:452) at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:411) at java.sql.DriverManager.getConnection(Unknown Source) at java.sql.DriverManager.getConnection(Unknown Source) at org.apache.jsp.connect1_jsp._jspService(connect1_jsp.java:48) at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98) at javax.servlet.http.HttpServlet.service(HttpServlet.java:803) at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:328) at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:315) at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265) at javax.servlet.http.HttpServlet.service(HttpServlet.java:803) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:210) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:870) at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665) at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528) at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81) at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:685) at java.lang.Thread.run(Unknown Source)** END NESTED EXCEPTION ** org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:846) org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:779) org.apache.jsp.connect1_jsp._jspService(connect1_jsp.java:67) org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98) javax.servlet.http.HttpServlet.service(HttpServlet.java:803) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:328) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:315) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265) javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
•
•
Join Date: Dec 2004
Location: London or Slovakia
Posts: 1,924
Reputation:
Rep Power: 9
Solved Threads: 221
Make shure your MySQL database is runnig ( I sometimes forget I switch it off)
I'm using Windows XP and my JDBC connector is in "C:\Program Files\Java\jdk1.6.0\jre\lib\ext" plus you should place there servlet-api.jar and jsp-api.jar which you can find in your Tomcat directory (in my case C:\Tomcat 5.5\common\lib)
This should take care of the problem, if no you still can chceck if you installed everything correctly on this site
One thing, you SHOULD NOT use JSP for connection to your database but you should use servlets. JSP is still capable of connecting to DB but this is left there for back compactibility with some old components. If you use book you should get newer edition, if is it teacher tell him/her to update his/her notes
I'm using Windows XP and my JDBC connector is in "C:\Program Files\Java\jdk1.6.0\jre\lib\ext" plus you should place there servlet-api.jar and jsp-api.jar which you can find in your Tomcat directory (in my case C:\Tomcat 5.5\common\lib)
This should take care of the problem, if no you still can chceck if you installed everything correctly on this site
One thing, you SHOULD NOT use JSP for connection to your database but you should use servlets. JSP is still capable of connecting to DB but this is left there for back compactibility with some old components. If you use book you should get newer edition, if is it teacher tell him/her to update his/her notes
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)
If we helped you to solve your problem, answered your question please mark your post as SOLVED.
Publilius Syrus
(~100 BC)
If we helped you to solve your problem, answered your question please mark your post as SOLVED.
•
•
Join Date: Nov 2004
Location: Netherlands
Posts: 5,588
Reputation:
Rep Power: 18
Solved Threads: 187
Do NOT put ANYTHING in the lib/ext directory of your JRE or JDK.
VERY VERY VERY bad!
Instead set up your classpath properly, as indicated in the documentation of the JDK. JRE, appservers, etc. etc. etc.
VERY VERY VERY bad!
Instead set up your classpath properly, as indicated in the documentation of the JDK. JRE, appservers, etc. etc. etc.
42 Private messages asking for help will be ignored
In the frozen land of Nador they were forced to eat Steve's iMinstrels, and there was much rejoicing.
In the frozen land of Nador they were forced to eat Steve's iMinstrels, and there was much rejoicing.
•
•
Join Date: Dec 2004
Location: London or Slovakia
Posts: 1,924
Reputation:
Rep Power: 9
Solved Threads: 221
•
•
•
•
Do NOT put ANYTHING in the lib/ext directory of your JRE or JDK.
VERY VERY VERY bad!
jwenting this is not hopefull ! Please can you explain...
It is the case that teacher at school tell you set up Java this way and that is. We do not question them. So you as the programmer with years of experience should explain or point to the place where appropriate resources avaible(and no just go to sun website and find it). Not to just drop a shell bomb saing "that is bad, bad..."
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)
If we helped you to solve your problem, answered your question please mark your post as SOLVED.
Publilius Syrus
(~100 BC)
If we helped you to solve your problem, answered your question please mark your post as SOLVED.
•
•
Join Date: Mar 2007
Posts: 7
Reputation:
Rep Power: 0
Solved Threads: 1
Hello !!
Thankx for all ur reply's. Actually i m very new to this jsp programming , i dont really know much abt all this, just followng a few books and tutorials to make it work, but i think u r right on all that they used the older versions that is not even available online, and may be i m having version incompatibility or version conflict problem.
Anyways can anyone tell me that if i am using apache-tomcat-5.5.23, so do i still need to install apache server separately and make connection with tomcat later on??
As I m using different working codes from some books and websites, they usually give me error on my connection string and some root errors like:
org.apache.jasper.JasperException: Unable to compile class for JSP:
org.apache.jasper.JasperException: Communication link failure: java.io.EOFException, underlying cause: null
My connection string is
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:8009/login? user=root&password=asma");
Root would be the default username as i haven't set it and "asma" would be the password that i set wile installing MySQL server.
My all other jsp pages working fine , only having problem in connecting with database.
I have tried ur suggestion of putting the files as well as seting CLASSPATH but neither of it worked.
I'll be thankful if anyone can help in this regard
Thankx for all ur reply's. Actually i m very new to this jsp programming , i dont really know much abt all this, just followng a few books and tutorials to make it work, but i think u r right on all that they used the older versions that is not even available online, and may be i m having version incompatibility or version conflict problem.
Anyways can anyone tell me that if i am using apache-tomcat-5.5.23, so do i still need to install apache server separately and make connection with tomcat later on??
As I m using different working codes from some books and websites, they usually give me error on my connection string and some root errors like:
org.apache.jasper.JasperException: Unable to compile class for JSP:
org.apache.jasper.JasperException: Communication link failure: java.io.EOFException, underlying cause: null
My connection string is
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:8009/login? user=root&password=asma");
Root would be the default username as i haven't set it and "asma" would be the password that i set wile installing MySQL server.
My all other jsp pages working fine , only having problem in connecting with database.
I have tried ur suggestion of putting the files as well as seting CLASSPATH but neither of it worked.
I'll be thankful if anyone can help in this regard
In mysql you not only have to create a user and set a password, you also have to designate from where (and how) that user is allowed to connect the DB. Per default, root can only connect from localhost using the sock file, but, in Java, you will be attempting to connect over TCP. So, read the MySQL documentation (namely the GRANT statement) and add a root@localhost entry.
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
•
•
Join Date: Nov 2004
Location: Netherlands
Posts: 5,588
Reputation:
Rep Power: 18
Solved Threads: 187
•
•
•
•
jwenting this is not hopefull ! Please can you explain...
It is the case that teacher at school tell you set up Java this way and that is. We do not question them. So you as the programmer with years of experience should explain or point to the place where appropriate resources avaible(and no just go to sun website and find it). Not to just drop a shell bomb saing "that is bad, bad..."
placing anything there will mask the real issues, which is that you have no clue about configuring your runtime properly (including classpath settings especially).
It's also guaranteed to lead to the Java equivalent of DLL Hell in short order, as many applications require different versions of the same libraries and those often conflict.
By placing one version there you're shoving it down the throat of every Java application you run on your system as the one and only true version, leading to all kinds of problems.
If you need a library, get it from where you can get it (which differs for each library) and add it to your classpath as required for the lifetime of the JVM when running the application.
So NO placing anything in lib/ext, NO global classpath settings.
42 Private messages asking for help will be ignored
In the frozen land of Nador they were forced to eat Steve's iMinstrels, and there was much rejoicing.
In the frozen land of Nador they were forced to eat Steve's iMinstrels, and there was much rejoicing.
•
•
Join Date: Mar 2007
Posts: 7
Reputation:
Rep Power: 0
Solved Threads: 1
•
•
•
•
In mysql you not only have to create a user and set a password, you also have to designate from where (and how) that user is allowed to connect the DB. Per default, root can only connect from localhost using the sock file, but, in Java, you will be attempting to connect over TCP. So, read the MySQL documentation (namely the GRANT statement) and add a root@localhost entry.
Hello
I have tried that option as well with command
GRANT ALL PRIVILEGES ON 'login'.* TO 'root'@'localhost:8009'
IDENTIFIED BY 'mdas' WITH GRANT OPTION;
but it still giving the error on connection string with the same communication link root cause:
exception org.apache.jasper.JasperException: Exception in JSP: /connect1.jsp:63: 4: <%5: Class.forName("com.mysql.jdbc.Driver").newInstance();6: Connection con = DriverManager.getConnection("jdbc:mysql://localhost:8009/login? user='root'&password='mdas'");7: Statement statement = con.createStatement();8: ResultSet rs = statement.executeQuery("SELECT message FROM users");9: Stacktrace: org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:467) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:371) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:315) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265) javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
root cause javax.servlet.ServletException: Communication link failure: java.io.EOFException, underlying cause: null** BEGIN NESTED EXCEPTION ** java.io.EOFExceptionSTACKTRACE:java.io.EOFException at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:1395) at com.mysql.jdbc.MysqlIO.readPacket(MysqlIO.java:1414) at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:625) at com.mysql.jdbc.Connection.createNewIO(Connection.java:1808) at com.mysql.jdbc.Connection.<init>(Connection.java:452) at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:411) at java.sql.DriverManager.getConnection(Unknown Source) at java.sql.DriverManager.getConnection(Unknown Source) at org.apache.jsp.connect1_jsp._jspService(connect1_jsp.java:48) at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98) at javax.servlet.http.HttpServlet.service(HttpServlet.java:803) at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:328) at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:315) at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265) at javax.servlet.http.HttpServlet.service(HttpServlet.java:803) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:210) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:870) at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665) at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528) at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81) at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:685) at java.lang.Thread.run(Unknown Source)** END NESTED EXCEPTION **
whta can i do please HELP ME.
What DB version are you using, and what version of the driver are you using.
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb JSP Marketplace
Similar Threads
- JSP shopping cart (JSP)
- JSP with MySql (JSP)
- connecting jsp with mysql database (JSP)
Other Threads in the JSP Forum
- Previous Thread: how to get servers date
- Next Thread: Help Needed in Struts-jsp



Linear Mode