Results 1 to 2 of 2
  1. #1
    simon is offline Member
    Join Date
    Jul 2007
    Posts
    44
    Rep Power
    0

    Default SQLException: Unable to connect to any hosts due to exception

    I connected to mysql and loaded the appropriate drivers, but this error appears:
    Java Code:
    ** BEGIN NESTED EXCEPTION **
    
    java.net.ConnectException
    MESSAGE: Connection refused: connect
    
    STACKTRACE:
    java.net.ConnectException: Connection refused: connect
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:305)
    ...
    ...
    ...
    SQLException: null

    my code is:
    Java Code:
    Connection conn = null;
    Statement stmt = null;
    ResultSet rs = null;
    
    try
    {
    Class.forName("com.mysql.jdbc.Driver").newInstance();
    conn = DriverManager.getConnection(url1, user1, pass1);
    stmt = conn.createStatement();
    System.out.println(query);
    rs = stmt.executeQuery(query);
    
    while(rs.next())
    {
    System.out.println(rs.getString("Titel") + "\n");
    }
    }
    
    catch (Exception ex)
    {
    System.out.println("SQLException: " + ex.getMessage());
    }
    any ideas?

  2. #2
    leonard is offline Member
    Join Date
    Jul 2007
    Posts
    43
    Rep Power
    0

    Default

    Did you check hibernate.properties?

    hibernate.connection.url jdbc:mysql://YourComputerName/test
    hibernate.connection.username root

Similar Threads

  1. Replies: 6
    Last Post: 09-01-2010, 11:29 AM
  2. Replies: 2
    Last Post: 06-07-2010, 08:45 AM
  3. Unable to get a XAConnection from the DataSource.
    By Eric in forum Enterprise JavaBeans (EJB)
    Replies: 3
    Last Post: 05-16-2008, 11:17 AM
  4. Replies: 1
    Last Post: 03-08-2008, 06:41 PM
  5. Unable to compile
    By gapper in forum New To Java
    Replies: 2
    Last Post: 01-14-2008, 04:31 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •