Ask Your Computer Question. Computer Experts Answer You ASAP.

(Not a Computer Question?)

I am trying to connect to a database on my imac 10.4.10.

Sent to Computer Experts July 22 04:06 PM

I am trying to connect to a database on my imac 10.4.10. Tomcat is started. mysql is started. When I view on my computer at:
http://localhost:8080/jspdbtodo/test.jsp

I am getting this error:

Unable to connect to any hosts due to exception: java.net.SocketException: java.net.ConnectException: Connection refused ** BEGIN NESTED EXCEPTION ** java.net.SocketException MESSAGE: java.net.ConnectException: Connection refused STACKTRACE: java.net.SocketException: java.net.ConnectException: Connection refused at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:143) at com.mysql.jdbc.MysqlIO.(MysqlIO.java:225) at com.mysql.jdbc.Connection.createNewIO(Connection.java:1805) at com.mysql.jdbc.Connection.(Connection.java:452) at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:411) at java.sql.DriverManager.getConnection(DriverManager.java:525) at java.sql.DriverManager.getConnection(DriverManager.java:171) at org.apache.jsp.test_jsp._jspService(test_jsp

 

Optional Information:
OS: Mac OS X; Browser: Firefox

Already Tried:
I have tomcat started. mysql started. The database was created like this in the terminal: create database macjava; grant all on macjava.* to javadev@localhost identified by "special"; the file that I bring up in tomcat is from this file test.jsp here is the code: <%@ page language="java" import="java.sql.*" %> <% Driver myDriver = null; Connection myConnection = null; String SQLstatement = "select now()"; try { String jdbcURL = "jdbc:mysql://localhost/macjava"; String jdbcUsername = "javadev"; String jdbcPassword = "special"; myDriver = (Driver)Class.forName("org.gjt.mm.mysql.Driver").newInstance(); myConnection = DriverManager.getConnection(jdbcURL, jdbcUsername, jdbcPassword); PreparedStatement myStatement; ResultSet myResults; myStatement = myConnection.prepareStatement(SQLstatement); myResults = myStatement.executeQuery(); while(myResults.next()) { %> <%= myResults.getString(1) %> <% } } catch (Exception e) { %> <%= e.getMessage() %> <% e.printStackTrace(); System.out.println(SQLstatement); return; } finally { try { myConnection.close(); } catch (Exception e) { /* Silent failure */} } %>

Customer (name blocked for privacy)
Answer
July 23 4:39 AM (12 hours and 32 minutes and 31 seconds later)
         
ACCEPTEDCheck Mark
I think this exception means your DB connection is getting rejected because of permissions.

Check two things:

First, with Mysql you must flush the db when you change premissions (I don't remember how you do this, CocoaMysql has a button for it).

Second, double check the DB URL you are using is correct and has the right password.

If this is the answer to your question, please kindly select * ACCEPT * so I can be rewarded for my efforts.


Thank you.
Please choose accept if this is what you are looking for.

Think you can answer this question?
Login or Become an Expert

 

DISCLAIMER: You acknowledge that any information you may obtain from individuals you contact through use of the JustAnswer service comes from those individuals, not from JustAnswer, and that JustAnswer is not in any way responsible for any of the information these third parties may supply. The site and services are provided "as is" with no warranty and no representations are made regarding the qualification of an Expert. Responses and comments on JustAnswer are for general information and are not intended to substitute for informed professional advice (such as medical, legal, investment or accounting) and do not establish a professional-client relationship. JustAnswer is not intended or designed to address EMERGENCY QUESTIONS which should be directed immediately by telephone or in-person to qualified professionals. Please carefully read the Terms of Service.

JustAnswer > Computer and Software Help