Getting problem in JDBC
Details of my s/w on my PC
OS: PCQLinux2005(full version), Servers: Apache,Tomcat,database: MySQL,
database name:airforce, user:airforce, pwd:airforce ,
privileges were given to user airforce on db airforce by the command
grant all on *.* to 'airforce'@localhost:8080' identified by 'airforce'
The Problem
The code in CadetBook.jsp is running when the OS is Win2k with Apache Tomcat and database is MS SQL Server but does not run in Linux with Apache Tomcat and MySQL database. I have changed the driver as
"org.gjt.mm.mysql.Driver"
CadetBook.jsp is called from CadetBook.htm consisting of entry fields.
When executing CadetBook.jsp (check below) i am getting the following error.
===========================================================
errorcom.mysql.jdbc.CommunicationsException: Communications link failure due to underlying
exception: ** BEGIN NESTED EXCEPTION ** java.io.EOFException STACKTRACE: java.io.EOFException at
com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:1845) at
com.mysql.jdbc.MysqlIO.readPacket(MysqlIO.java:476) at
com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:947) at
com.mysql.jdbc.Connection.createNewIO(Connection.java:1702) at
com.mysql.jdbc.Connection.(Connection.java:405) at
com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:268) at
java.sql.DriverManager.getConnection(DriverManager.java:525) at
java.sql.DriverManager.getConnection(DriverManager.java:171) at
org.apache.jsp.airforce.CadetBook_jsp._jspService(org.apache.jsp.airforce.CadetBook_jsp:60) at
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:99) at
javax.servlet.http.HttpServlet.service(HttpServlet.java:802) at
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:325) at
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295) at
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:245) at
javax.servlet.http.HttpServlet.service(HttpServlet.java:802) at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157) at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214) at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178) at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126) at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105) at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107) at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148) at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:825) at
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.
java:731) at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:526)
at
org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684) at
java.lang.Thread.run(Thread.java:595) ** END NESTED EXCEPTION **
=========================================
The table i am using
Table CadetBook
================
CREATE TABLE cadetbook (
slno varchar (50) ,
sdate varchar (50) ,
serno varchar (50) ,
tin varchar (50) ,
tout varchar (50) ,
path varchar (50) ,
auth varchar (50)
)
================
The jsp code i am using
CadetBook.jsp
================
<%@ page import="java.sql.*"%>
<%@ page import="java.io.*"%>
<%@ page import="java.util.*" %>
<html>
<body>
<%
try {
try {
Class.forName("org.gjt.mm.mysql.Driver");
} catch (Exception ex) {
System.out.println("Error while loading the Driver : " + ex);
}
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:8080/airforce" , "airforce"
, "airforce");
Statement st=con.createStatement();
int i=st.executeUpdate("insert into cadetbook values('" + request.getParameter("slno") + "','" +
request.getParameter("sdate") + "','" + request.getParameter("serno") + "','" +
request.getParameter("tin") + "','" + request.getParameter("tout") + "','" +
request.getParameter("path") + "','" + request.getParameter("auth") + "')");
if (i==1)
out.println("Record Inserted.");
else
out.println("Record not Inserted.");
} catch (Exception e) {out.println("error"+e);}%>
</body>
</html>
================
|