Solved

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

Posted on 2004-03-24
3
1,841 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 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

Why You Need a DevOps Toolchain

IT needs to deliver services with more agility and velocity. IT must roll out application features and innovations faster to keep up with customer demands, which is where a DevOps toolchain steps in. View the infographic to see why you need a DevOps toolchain.

Question has a verified solution.

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

All XML, All the Time; More Fun MySQL Tidbits – Dynamically Generate XML via Stored Procedure in MySQL Extensible Markup Language (XML) and database systems, a marriage we are seeing more and more of.  So the topics of parsing and manipulating XM…
I use MySQL for many of my development projects in a Windows environment. To manage my databases (and perform queries) for years I used a tool called MySQL administrator.  This tool has since been replaced by MySQL Workbench. So I decided to m…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

731 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