Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2004-03-24
3
Medium Priority
?
1,892 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
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

Enroll in September's Course of the Month

This month’s featured course covers 16 hours of training in installation, management, and deployment of VMware vSphere virtualization environments. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
Backups and Disaster RecoveryIn this post, we’ll look at strategies for backups and disaster recovery.
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

670 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