Results 41 to 58 of 58
- 09-13-2011, 12:41 PM #41
Member
- Join Date
- Aug 2011
- Posts
- 25
- Rep Power
- 0
- 09-14-2011, 01:10 PM #42
Member
- Join Date
- Aug 2011
- Posts
- 25
- Rep Power
- 0
Re: [MySQL][Jar] Problems outside the IDE
Nobody can help me with this? I just don't know what else to do... I will provide the .jar file, I hope that someone can help me...
Cadastro.jar - 4shared.com - online file sharing and storage - download
ps.: The comments on the code are in portuguese, hope it doesn't matter (Encoding:UTF-8).
- 09-14-2011, 01:15 PM #43
Re: [MySQL][Jar] Problems outside the IDE
Your problem is getting the all the classes on the classpath. One thing that makes it harder is having your class in a package. Remove the package statement and you wouldn't have to worry about putting your classes in the correct folder.
- 09-14-2011, 01:27 PM #44
Member
- Join Date
- Aug 2011
- Posts
- 25
- Rep Power
- 0
Re: [MySQL][Jar] Problems outside the IDE
I tried this but I got all the same problems as before.
By the way who try to run my code may need the this to create a db (You need to change the class ConnectionDataBase as well)
CREATE TABLE `dados` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`nome` varchar(200) NOT NULL,
`idade` varchar(200) NOT NULL,
`data_nascimento` date NOT NULL,
`alergias` varchar(200) NOT NULL,
`peso` varchar(5) NOT NULL,
`altura` varchar(6) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=latin1
- 09-14-2011, 01:30 PM #45
Re: [MySQL][Jar] Problems outside the IDE
Please show the full text of the error message.I got all the same problems as before.
- 09-14-2011, 01:35 PM #46
Member
- Join Date
- Aug 2011
- Posts
- 25
- Rep Power
- 0
Re: [MySQL][Jar] Problems outside the IDE
Can't Connect to Database
Exception in thread "main" java.lang.RuntimeException: com.mysql.jdbc.exceptions.MySQLSyntaxErrorExceptio n: 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(ConnectionDataBas e.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.MySQLSyntaxErrorExceptio n: 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(SQLErro r.java:1049)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.ja va:3597)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.ja va:3529)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:19 90)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java :2151)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionIm pl.java:2619)
at com.mysql.jdbc.ConnectionImpl.configureClientChara cterSet(ConnectionImpl.java:1881)
at com.mysql.jdbc.ConnectionImpl.initializePropsFromS erver(ConnectionImpl.java:3496)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(Co nnectionImpl.java:2385)
at com.mysql.jdbc.ConnectionImpl.createNewIO(Connecti onImpl.java:2154)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImp l.java:792)
at com.mysql.jdbc.ConnectionImpl.getInstance(Connecti onImpl.java:377)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonReg isteringDriver.java:305)
at java.sql.DriverManager.getConnection(libgcj.so.11)
at java.sql.DriverManager.getConnection(libgcj.so.11)
at ConnectionDataBase.getConnection(ConnectionDataBas e.java:26)
...5 more
- 09-14-2011, 01:39 PM #47
Re: [MySQL][Jar] Problems outside the IDE
This looks like your SQL is wrong.You have an error in your SQL syntax;
Your code is executing, now you must fix your SQL.
- 09-14-2011, 01:45 PM #48
Member
- Join Date
- Aug 2011
- Posts
- 25
- Rep Power
- 0
Re: [MySQL][Jar] Problems outside the IDE
I can't get how it is wrong if it works on the IDE, I've already checked my SQL code (Class DadosDao) and it seens to be right, the problem must be when the code needs to run outside the IDE.... what doesn't make sense for me....
- 09-14-2011, 01:52 PM #49
Re: [MySQL][Jar] Problems outside the IDE
Try debugging by adding a println to show the SQL statement. Then run the code in the IDE and outside of the IDE and compare what was printed out to see if there is a difference.
- 09-14-2011, 02:16 PM #50
Member
- Join Date
- Aug 2011
- Posts
- 25
- Rep Power
- 0
Re: [MySQL][Jar] Problems outside the IDE
Ok, I think I've found my problem.
Outside the IDE I get the message "Can't connect to the database" (that is a SQL Exception)
So I tried to debug everywhere that I had a SQL Exception.
I get all these prints on the IDE (and just them,after connection sucess, 16, 17, 18....).
But outside the IDE, It ends on "Can't connect to the database" and shows the error messages
And again I don't know what else to do hehe.
This is the class that connects to the database
This is the where the prints 16, 17, 18 ... are.Java Code: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; } }
Java Code:public List<Dados> findDados() throws SQLException { System.out.println("16"); List<Dados> info = new ArrayList<Dados>(); System.out.println("17"); String select = "SELECT * FROM dados"; System.out.println("18"); Connection connection = getConnection(); System.out.println("19"); System.out.println(connection); System.out.println("20"); PreparedStatement stmt = getConnection().prepareStatement(select); System.out.println("21"); ResultSet rs = stmt.executeQuery(); while (rs.next()) { System.out.println("22"); Dados dados = new Dados(); System.out.println("23"); dados.setId(rs.getLong("id")); System.out.println("24"); dados.setNome(rs.getString("nome")); System.out.println("25"); dados.setIdade(rs.getString("idade")); dados.setDtNascimento(rs.getDate("data_nascimento")); dados.setAlergias(rs.getString("alergias")); dados.setPeso(rs.getString("peso")); dados.setAltura(rs.getString("altura")); dados.setImagem(rs.getString("imagem")); info.add(dados); } rs.close(); stmt.close(); return info; }
- 09-14-2011, 02:17 PM #51
Moderator
- Join Date
- Apr 2009
- Posts
- 10,460
- Rep Power
- 16
Re: [MySQL][Jar] Problems outside the IDE
It's not the SQL they're using, look at the stacktrace:
at java.sql.DriverManager.getConnection(libgcj.so.11)
at ConnectionDataBase.getConnection(ConnectionDataBas e.java:26)
That's not an execute...that's trying to get the connection.
Something about the IDE environment and the command line environment is different. And I doubt it's something we here could debug. I would suggest taking this to a MySQL forum maybe? They might know what goes on inside the driver.
- 09-14-2011, 02:21 PM #52
Moderator
- Join Date
- Apr 2009
- Posts
- 10,460
- Rep Power
- 16
Re: [MySQL][Jar] Problems outside the IDE
What Java are you running this against?
Both in the IDE and on the box?
- 09-14-2011, 02:31 PM #53
Member
- Join Date
- Aug 2011
- Posts
- 25
- Rep Power
- 0
Re: [MySQL][Jar] Problems outside the IDE
Tolls, couldn't get your question, can you explain ? (it might be my english hehe)
- 09-14-2011, 02:36 PM #54
Moderator
- Join Date
- Apr 2009
- Posts
- 10,460
- Rep Power
- 16
Re: [MySQL][Jar] Problems outside the IDE
What Java are you using?
libgcj implies you are on a *nix box of some sort, so I wanted to check what java you were using.
And then see whether it is different to the one being used by your IDE.
For example, if your box is using open java and the IDE had some form of Sun/Oracle Java then that could be your problem.
- 09-14-2011, 02:47 PM #55
Member
- Join Date
- Aug 2011
- Posts
- 25
- Rep Power
- 0
Re: [MySQL][Jar] Problems outside the IDE
Command on UNIX (Ubuntu):
java -version
java version "1.5.0"
gij (GNU libgcj) version 4.5.2
IDE:
JDK 7 with NetBeans 7.0.1
Can't tell if it is a problem or not
- 09-14-2011, 03:00 PM #56
Moderator
- Join Date
- Apr 2009
- Posts
- 10,460
- Rep Power
- 16
Re: [MySQL][Jar] Problems outside the IDE
There you go.
I would lay good odds that it's a mix of the compiling of your Java in a later version (your JDK is 7, your jar file says 6, you're running on 5), and using gnu java and not an Oracle one.
- 09-14-2011, 03:22 PM #57
Member
- Join Date
- Aug 2011
- Posts
- 25
- Rep Power
- 0
Re: [MySQL][Jar] Problems outside the IDE
I tried to update my Java but it says that I already got the latest version... any tips of how try to solve this mix os versions? Thanks for the patience!
- 09-14-2011, 03:45 PM #58
Moderator
- Join Date
- Apr 2009
- Posts
- 10,460
- Rep Power
- 16
Similar Threads
-
Problems using MySQL database
By Antrim in forum EclipseReplies: 1Last Post: 02-16-2011, 04:57 AM -
Problems with MySQL Driver
By islan in forum JDBCReplies: 7Last Post: 08-06-2009, 04:47 PM -
MySQL/JDBC Mysql query output
By thelinuxguy in forum Advanced JavaReplies: 4Last Post: 02-13-2009, 01:57 AM -
hello the community & mysql connecting problems
By scchia in forum New To JavaReplies: 6Last Post: 07-16-2008, 08:49 AM -
problems about storing binary data to mysql db using PreparedStatement
By xiechao in forum New To JavaReplies: 0Last Post: 04-22-2008, 11:57 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks