Posted By:
Brad_Birdwell
Posted On:
Thursday, July 8, 2004 08:22 AM
I have installed Apache Tomcat 5 on my system. I also have a working copy of MySQL on my system hosting several databases that I need to access via some java programs that I have. At one time I was hosting these same applications on my windows machine which allowed me to use odbc connections but now they are on a new linux machine. Everything on the machine works great except I can not access the database from java. first: The mysql connector jar file. I have tried it in different locations because every how to says something different. These include java/lib/bin, tomcat/common/lib (webapp)/web-inf/lib. I have added the location of the file to the classpath variable. None of these seemed to change the error message that I got. The Cod
More>>
I have installed Apache Tomcat 5 on my system. I also have a working copy of MySQL on my system hosting several databases that I need to access via some java programs that I have. At one time I was hosting these same applications on my windows machine which allowed me to use odbc connections but now they are on a new linux machine. Everything on the machine works great except I can not access the database from java.
first:
The mysql connector jar file. I have tried it in different locations because every how to says something different. These include java/lib/bin, tomcat/common/lib (webapp)/web-inf/lib. I have added the location of the file to the classpath variable. None of these seemed to change the error message that I got.
The Code:
The java code that I am currently using to connect to the database is:
import java.sql.*;
public class connection {
public Connection connect()
{
Connection conn = null;
String username = "UserName";//Insert Username Here
String password = "Password";//Insert Password Here
String url = "jdbc:mysql://127.0.0.1:3306/test";//Change Database if needed
Connection con = null;
try {
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection
(url,username,password);
}
catch (Exception e)
{
System.err.println ("Cannot connect to database server");
System.err.println (e.getMessage());
}
return con;
}
}
The Error:
2004-07-08 09:56:46 StandardWrapperValve[authenticate]: Servlet.service() for servlet authenticate threw exception
java.lang.NullPointerException
at authenticate.doPost(authenticate.java:23)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
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.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:793)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:702)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:571)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:644)
at java.lang.Thread.run(Unknown Source)
I have a good feeling that the java application is not loading the driver file correctly but I do not know how to solve this problem. Any help would be greatly appreciated.
Thanks
<<Less