Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2004-03-24
3
Medium Priority
?
1,906 Views
Last Modified: 2012-08-13
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?
0
Comment
Question by:iNspirito
1 Comment
 
LVL 2

Accepted Solution

by:
Neogenix earned 500 total points
ID: 10685701
Hi iNspirito,

You are almost there.

String url = "jdbc:mysql://localhost:3306/database?user=username&password=password";
conn = DriverManager.getConnection (url);

That is all you need.

Regards,

M
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month6 days, 22 hours left to enroll

783 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question