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:/t mp/mysql.s ock/databa se";
System.out.println("mes cia");
Class.forName("com.mysql.j dbc.Driver ").newInst ance();
System.out.println("driver is inecializuotas...");
conn = DriverManager.getConnectio n (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.NumberFormatExc eption: For input string: "tmp"'.
at com.mysql.jdbc.NonRegister ingDriver. connect(No nRegisteri ngDriver.j ava:409)
so how to connect to /tmp/mysql.sock using 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:/t
System.out.println("mes cia");
Class.forName("com.mysql.j
System.out.println("driver
conn = DriverManager.getConnectio
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.NumberFormatExc
at com.mysql.jdbc.NonRegister
so how to connect to /tmp/mysql.sock using JDBC driver?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.