1

I am creating a dynamic web project in eclipse. I have my local apache server running and configured with appropriate resource, mysql running and configured with the appropriate port.

I downloaded the appropriate driver, included it in the lib directory - I even tried adding it as an external JAR file to no avail. On the dynamic web page the result is "error connecting to database".

I created a JSP with the following code:

<%@ page import="java.sql.*"%><%@ page import="java.io.*"%><%@ page import="com.mysql.*"%><?xml version="1.0"?>

<tours>
<%
 Connection connection = null;
 Statement statement = null;
 ResultSet result = null;

 try {
     Class.forName("com.mysql.jdbc.Driver").newInstance();
     connection = DriverManager.getConnection("jbdc:mysql://localhost:3306/tours", "root", "root");
     out.println("connected to database!");
 }
 catch(SQLException e) {
     out.print("error connecting to database");
 }
%>


</tours>

Please advise...

Thanks in advance.

1
  • Change out.print("error connecting to database"); to out.print(e.getMessage()); and you'll likely discover the cause of your problem. Commented Jul 19, 2014 at 6:12

4 Answers 4

1

Put print after Class.forName() check, if that statement is not printing then problem is driver if that line is printing then problem is mysql database name problem or credential problem

If problem in drive then download from here :

http://www.java2s.com/Code/Jar/c/Downloadcommysqljdbc515jar.htm

Problem is u put jbdc instead of jdbc

Code like this

<%
 Connection connection = null;
 Statement statement = null;
 ResultSet result = null;

 try {
     Class.forName("com.mysql.jdbc.Driver").newInstance();
     out.println("Driver is available !");
   connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/tours",
    "root", "root");
     out.println("connected to database!");
 }
 catch(SQLException e) {
     out.print("error connecting to database");
 }
%>
Sign up to request clarification or add additional context in comments.

13 Comments

MAMP - MySQL config.: Host localhost Port 3306 User root Password root Table name is ‘tours’. Project name and JAR path: using_drivers/WebContent/WEB-INF/lib/mysql-connector-java-5.1.31-bin.jar
Driver is available ! error connecting to database That’s a great start! I will attempt the new driver download...
You should put the database name instead of table name "tours"
tours is the DB name. The table name is tour.
Problem is u put jbdc instead of jdbc
|
0

There are couple of things to take care of here. 1. Make sure that mysql is listening on port 3306. 2. Cross check the database name.

Lastly get the driver jar file in deployment assembly.

If the problem still persists, please print the stacktrace and post it here.

9 Comments

Host localhost Port 3306 User root Password root
Please print and post stacktrace.
Jul 19, 2014 2:21:38 AM org.apache.catalina.core.AprLifecycleListener init INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /Users/rollinfrancois/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:. Jul 19, 2014 2:21:39 AM org.apache.tomcat.util.digester.SetPropertiesRule begin
Looks like you are missing some dependencies in your classpath. Make sure you have all the required libraries.
I had to remove eclipse completely, then reinstall it. I did this and reconfigured everything. Now I am getting a HTTP Status 404 - "The requested resource is not available."
|
0

Please check weather your database is started or not i know it should be in comment but i cannot keep it in comment because i don't have sufficient reputations. please try it if it helps you it is fine.

How to start database is shown below:

Click Windows button+r then enter Services.msc in search bar then select Mysql and click start option

1 Comment

MAMP - Mac. DB is running.
0

Printing the stack trace might help it could be because of authorization issue. If the error is related to authorization issue, you may have to change the server configurations.

1 Comment

org.apache.catalina.core.AprLifecycleListener init INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /Users/rollinfrancois/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:. org.apache.tomcat.util.digester.SetPropertiesRule begin WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:using_drivers' did not find a matching property.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.