I tried to solve this problem on a Java forum, but after weeks of discussion they pointed me other solution - Try a MySQL Forum.
I'll try to explain my problem in few words.
My code works very well inside the IDE, but when I try to use it outside the ide (.jar file) it doesn't work, I got several SQL problems
I'll show the class that makes the connection to the database, the erros that I got and my tries to debug it. If you want to read all the discussion the link to the Java forum is
http://www.java-forums.org/new-java/47946-mysql-jar-problems-outside-ide.html
ConnectionDataBase class
Inside the IDE (NetBeans 7.0) it works perfectly(and the message "Conectado com sucesso!"), but outside it I get a SQL Exception (and the message "Can't connect to the Database")
public class ConnectionDataBase {
private static final String URL_MYSQL = "jdbc:mysql://localhost:3306/hospital";
private static final String DRIVER_CLASS = "com.mysql.jdbc.Driver";
private static final String USER = "root";
private static final String PASS = "lsa1234";
public static Connection getConnection()
{
System.out.println("Conectando ao Banco de Dados");
try
{
//Carrega o Driver do Banco
Class.forName(DRIVER_CLASS);
Connection conn = DriverManager.getConnection(URL_MYSQL, USER, PASS);
if (conn != null) {
System.out.println("STATUS--->Conectado com sucesso!");
} else {
System.out.println("STATUS--->Não foi possivel realizar conexão");
}
return conn;
}
catch (ClassNotFoundException e)
{
System.out.println("O driver expecificado nao foi encontrado.");
e.printStackTrace();
}
catch (SQLException e)
{
System.out.println("Can't connect to the database.");
throw new RuntimeException(e);
}
return null;
}
}
These are the errors outside the IDE
]Exception in thread "main" java.lang.RuntimeException: com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '????????????????' at line 1
at ConnectionDataBase.getConnection(ConnectionDataBase.java:48)
at GenericDao.<init>(GenericDao.java:19)
at DadosDao.<init>(DadosDao.java:17)
at DadosController.listaDados(DadosController.java:65)
at Principal.<init>(Principal.java:35)
at Cadastro.main(Cadastro.java:12)
Caused by: com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '????????????????' at line 1
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1049)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3597)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3529)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1990)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2151)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2619)
at com.mysql.jdbc.ConnectionImpl.configureClientCharacterSet(ConnectionImpl.java:1881)
at com.mysql.jdbc.ConnectionImpl.initializePropsFromServer(ConnectionImpl.java:3496)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2385)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2154)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:792)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:377)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:305)
at java.sql.DriverManager.getConnection(libgcj.so.11)
at java.sql.DriverManager.getConnection(libgcj.so.11)
at ConnectionDataBase.getConnection(ConnectionDataBase.java:26)
...5 more