Problema kon debian + JAVA ?
Nas , toi haciendo una aplikazión en java bajo linex (debian woody) , en la kual tengo k acceder a mysql , y me da el siguiente error , k voi a postear a continuación , lo kurioso es k via web (phpMyadmin) o via konsola (mysql) , puedo acceder ... Pero desde java no , buskando en varios foros .. Enkontré k la demás gente tiene el mismo problema k io , a ver si alguien me hecha 1 mano..
<b>El codigo es</b>
private Connection init_conn() throws Exception{
Connection conn = null;
String database= "jdbc:mysql://localhost/xanatel_com";
String username="user";
String password="password";
try {
//Class.forName("com.mysql.jdbc.Driver").newInstance();
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
conn = DriverManager.getConnection(database, username, password);
conn.setAutoCommit(false);
System.err.println("Connectat a: " + database);
return(conn);
} catch (Exception e) {
System.err.println("Error en connexio: " + e.getMessage());
e.printStackTrace();
conn = null;
return(conn);
}
}
<b>**************************</b>
Error en connexio: Cannot connect to MySQL server on localhost:3306. Is there a MySQL server running on the machine/port you are trying to connect to? (java.net.ConnectException)
java.sql.SQLException: Cannot connect to MySQL server on localhost:3306. Is there a MySQL server running on the machine/port you are trying to connect to? (java.net.ConnectException)
at com.mysql.jdbc.Connection.connectionInit(Unknown Source)
at com.mysql.jdbc.jdbc2.Connection.connectionInit(Unknown Source)
at com.mysql.jdbc.Driver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(DriverManager.java:512)
at java.sql.DriverManager.getConnection(DriverManager.java:171)
at Add_unitats.init_conn(Add_unitats.java:38)
at Add_unitats.execute(Add_unitats.java:65)
at Add_unitats.main(Add_unitats.java:77)
Exception in thread "main" java.lang.NullPointerException
at Add_unitats.add(Add_unitats.java:53)
at Add_unitats.execute(Add_unitats.java:70)
at Add_unitats.main(Add_unitats.java:77)
~
Thxs , rAdGe
<b>El codigo es</b>
private Connection init_conn() throws Exception{
Connection conn = null;
String database= "jdbc:mysql://localhost/xanatel_com";
String username="user";
String password="password";
try {
//Class.forName("com.mysql.jdbc.Driver").newInstance();
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
conn = DriverManager.getConnection(database, username, password);
conn.setAutoCommit(false);
System.err.println("Connectat a: " + database);
return(conn);
} catch (Exception e) {
System.err.println("Error en connexio: " + e.getMessage());
e.printStackTrace();
conn = null;
return(conn);
}
}
<b>**************************</b>
Error en connexio: Cannot connect to MySQL server on localhost:3306. Is there a MySQL server running on the machine/port you are trying to connect to? (java.net.ConnectException)
java.sql.SQLException: Cannot connect to MySQL server on localhost:3306. Is there a MySQL server running on the machine/port you are trying to connect to? (java.net.ConnectException)
at com.mysql.jdbc.Connection.connectionInit(Unknown Source)
at com.mysql.jdbc.jdbc2.Connection.connectionInit(Unknown Source)
at com.mysql.jdbc.Driver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(DriverManager.java:512)
at java.sql.DriverManager.getConnection(DriverManager.java:171)
at Add_unitats.init_conn(Add_unitats.java:38)
at Add_unitats.execute(Add_unitats.java:65)
at Add_unitats.main(Add_unitats.java:77)
Exception in thread "main" java.lang.NullPointerException
at Add_unitats.add(Add_unitats.java:53)
at Add_unitats.execute(Add_unitats.java:70)
at Add_unitats.main(Add_unitats.java:77)
~
Thxs , rAdGe
Respuesta de gbas
1