Solved

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

Posted on 2004-03-24
3
1,797 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
3 Comments
 
LVL 2

Accepted Solution

by:
Neogenix earned 125 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

707 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now