Page 3 of 3 FirstFirst 123
Results 41 to 58 of 58
  1. #41
    Revoke is offline Member
    Join Date
    Aug 2011
    Posts
    25
    Rep Power
    0

    Default Re: [MySQL][Jar] Problems outside the IDE

    Inside the IDE it works perfectly.

    I'm using NetBeans 7.0

  2. #42
    Revoke is offline Member
    Join Date
    Aug 2011
    Posts
    25
    Rep Power
    0

    Default 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).

  3. #43
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,272
    Rep Power
    25

    Default 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.

  4. #44
    Revoke is offline Member
    Join Date
    Aug 2011
    Posts
    25
    Rep Power
    0

    Default 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

  5. #45
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,272
    Rep Power
    25

    Default Re: [MySQL][Jar] Problems outside the IDE

    I got all the same problems as before.
    Please show the full text of the error message.

  6. #46
    Revoke is offline Member
    Join Date
    Aug 2011
    Posts
    25
    Rep Power
    0

    Default 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

  7. #47
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,272
    Rep Power
    25

    Default Re: [MySQL][Jar] Problems outside the IDE

    You have an error in your SQL syntax;
    This looks like your SQL is wrong.
    Your code is executing, now you must fix your SQL.

  8. #48
    Revoke is offline Member
    Join Date
    Aug 2011
    Posts
    25
    Rep Power
    0

    Default 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....

  9. #49
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,272
    Rep Power
    25

    Default 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.

  10. #50
    Revoke is offline Member
    Join Date
    Aug 2011
    Posts
    25
    Rep Power
    0

    Default 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

    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;
        }
    }
    This is the where the prints 16, 17, 18 ... are.

    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;
        }

  11. #51
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,755
    Rep Power
    19

    Default 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.

  12. #52
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,755
    Rep Power
    19

    Default Re: [MySQL][Jar] Problems outside the IDE

    What Java are you running this against?
    Both in the IDE and on the box?

  13. #53
    Revoke is offline Member
    Join Date
    Aug 2011
    Posts
    25
    Rep Power
    0

    Default Re: [MySQL][Jar] Problems outside the IDE

    Tolls, couldn't get your question, can you explain ? (it might be my english hehe)

  14. #54
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,755
    Rep Power
    19

    Default 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.

  15. #55
    Revoke is offline Member
    Join Date
    Aug 2011
    Posts
    25
    Rep Power
    0

    Default 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

  16. #56
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,755
    Rep Power
    19

    Default 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.

  17. #57
    Revoke is offline Member
    Join Date
    Aug 2011
    Posts
    25
    Rep Power
    0

    Default 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!

  18. #58
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,755
    Rep Power
    19

    Default Re: [MySQL][Jar] Problems outside the IDE

    You probably do, for gnu java.
    You need to install an Oracle one.

    Or downgrade your development JDK to 1.5, but I wouldn't guarantee that that would work. What version of the driver are you using? I wonder if it's too new to work with a 1.5 java.

Page 3 of 3 FirstFirst 123

Similar Threads

  1. Problems using MySQL database
    By Antrim in forum Eclipse
    Replies: 1
    Last Post: 02-16-2011, 04:57 AM
  2. Problems with MySQL Driver
    By islan in forum JDBC
    Replies: 7
    Last Post: 08-06-2009, 04:47 PM
  3. MySQL/JDBC Mysql query output
    By thelinuxguy in forum Advanced Java
    Replies: 4
    Last Post: 02-13-2009, 01:57 AM
  4. hello the community & mysql connecting problems
    By scchia in forum New To Java
    Replies: 6
    Last Post: 07-16-2008, 08:49 AM
  5. Replies: 0
    Last Post: 04-22-2008, 11:57 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •