Link to home
Start Free TrialLog in
Avatar of iNspirito
iNspirito

asked on

connecting to /tmp/mysql.sock MySQL using JDBC driver

Is it possible to use /tmp/mysql.sock socket in JDBC driver?
I am writing program in JAVA which connects to MySQL server over /tmp/mysqk.sock and I don't know the right way how to use mysql.sock in JDBC driver.

source:

import java.sql.*;

   public class Connect
   {
       public static void main (String[] args)
       {
         Connection conn = null;

           try
           {
               String userName = "user";
               String password = "pass";
               String url = "jdbc:mysql://localhost:/tmp/mysql.sock/database";
                     System.out.println("mes cia");
                     Class.forName("com.mysql.jdbc.Driver").newInstance();
                     System.out.println("driveris inecializuotas...");

               conn = DriverManager.getConnection (url, userName, password);
               System.out.println ("prisijungimas brie duombazes sekmingas...");
           }
           catch (Exception e)
           {
               e.printStackTrace();
             System.err.println ("neimanoma prisijungti prie duombazes");
           }
           finally
           {
               if (conn != null)
               {
                   try
                   {
                       conn.close ();
                       System.out.println ("jungimasis nutrauktas");
                   }
                   catch (Exception e) { /* ignore close errors */ }
               }
           }
                    while(true) {
         }

       }
   }

and I get erro because of using /tmp/mysql.sock :

java.sql.SQLException: Cannot load connection class because of underlying exception: 'java.lang.NumberFormatException: For input string: "tmp"'.
        at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:409)

so how to connect to /tmp/mysql.sock using JDBC driver?
ASKER CERTIFIED SOLUTION
Avatar of Neogenix
Neogenix

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial