Page 2 of 3 FirstFirst 123 LastLast
Results 21 to 40 of 58
  1. #21
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,512
    Blog Entries
    7
    Rep Power
    20

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

    Quote Originally Posted by Revoke View Post
    Norm
    I'm using this to run the .jar file

    java -jar "/home/lsa/NetBeansProjects/Cadastro/dist/Cadastro.jar"

    How do I add the jar file to the classpath?
    Simply do this for now:

    Java Code:
    java -cp/path/to/jar/that/contains/your/sqldriver -jar "/home/lsa/NetBeansProjects/Cadastro/dist/Cadastro.jar"
    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

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

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

    Quote Originally Posted by JosAH View Post
    Simply do this for now:

    Java Code:
    java -cp/path/to/jar/that/contains/your/sqldriver -jar "/home/lsa/NetBeansProjects/Cadastro/dist/Cadastro.jar"
    kind regards,

    Jos
    Thanks for the tip Jos but I got the same errors

    I tried
    Java Code:
    java -cp "/home/lsa/Downloads/mysql-connector-java-5.1.17" -jar "/home/lsa/NetBeansProjects/Cadastro/dist/Cadastro.jar"

  3. #23
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,512
    Blog Entries
    7
    Rep Power
    20

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

    Quote Originally Posted by Revoke View Post
    Thanks for the tip Jos but I got the same errors

    I tried
    Java Code:
    java -cp "/home/lsa/Downloads/mysql-connector-java-5.1.17" -jar "/home/lsa/NetBeansProjects/Cadastro/dist/Cadastro.jar"
    Doesn't that file end with the extension ".jar"?

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  4. #24
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,001
    Rep Power
    20

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

    OK, so this is nothing to do with the jar file not being found.
    Presumably your classpath in the MANIFEST is now OK?

    Because if it isn't then I would ask where this code thinks it's getting its driver from...

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

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

    Quote Originally Posted by JosAH View Post
    Doesn't that file end with the extension ".jar"?

    kind regards,

    Jos
    Oh yeah sorry, but still the same errors

    Java Code:
    java -cp "/home/lsa/Downloads/mysql-connector-java-5.1.17-bin.jar" -jar "/home/lsa/NetBeansProjects/Cadastro/dist/Cadastro.jar"

  6. #26
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,001
    Rep Power
    20

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

    Quote Originally Posted by JosAH View Post
    Doesn't that file end with the extension ".jar"?

    kind regards,

    Jos
    Does -cp work with -jar?
    Quoting the docs:
    When you use this option, the JAR file is the source of all user classes, and other user class path settings are ignored.
    I would always use the manifest for executable jar files.

  7. #27
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,512
    Blog Entries
    7
    Rep Power
    20

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

    Quote Originally Posted by Revoke View Post
    Oh yeah sorry, but still the same errors

    Java Code:
    java -cp "/home/lsa/Downloads/mysql-connector-java-5.1.17-bin.jar" -jar "/home/lsa/NetBeansProjects/Cadastro/dist/Cadastro.jar"
    What errors? null for the Connection? Or is it something else now?

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

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

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

    Quote Originally Posted by JosAH View Post
    What errors? null for the Connection? Or is it something else now?

    kind regards,

    Jos
    these errors

    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 cadastro.dao.ConnectionDataBase.getConnection(Conn ectionDataBase.java:48)
    at cadastro.dao.GenericDao.<init>(GenericDao.java:19)
    at cadastro.dao.DadosDao.<init>(DadosDao.java:16)
    at cadastro.controller.DadosController.listaDados(Dad osController.java:65)
    at cadastro.Principal.<init>(Principal.java:33)
    at cadastro.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 cadastro.dao.ConnectionDataBase.getConnection(Conn ectionDataBase.java:26)
    ...5 more


    Tolls

    How do I check the classpath in the MANIFEST ?
    I really don't know what it is

  9. #29
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,387
    Rep Power
    25

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

    I don't think you can mix the -cp and the -jar options. Put the jar files on the classpath and explicitly invoke your class. I used the : for separator here. Change it to what is correct on your OS
    java -cp /home/lsa/Downloads/mysql-connector-java-5.1.17-bin.jar:/home/lsa/NetBeansProjects/Cadastro/dist/Cadastro.jar cadastro.Cadastro

  10. #30
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,001
    Rep Power
    20

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

    Quote Originally Posted by Revoke View Post
    Tolls

    How do I check the classpath in the MANIFEST ?
    I really don't know what it is
    Read the Manifest, as suggested by Norm earlier in the thread.
    It's a file inside the jar file, in the META-INF directory.

    Or run it as Norm is suggesting.

    However, if you are getting the above exceptions then the jar file must already be accessible, otherwise you would not see that stack trace.

    Now...if the manifest does not have the driver jar file listed, then I can only think you have unzipped the jar file, which is not a good idea.

  11. #31
    Revoke is offline Member
    Join Date
    Aug 2011
    Posts
    25
    Rep Power
    0

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

    I tried this

    Java Code:
    CLASSPATH=.:$CLASSPATH:/home/lsa/Downloads/mysql-connector-java-5.1.17/mysql-connector-java-5.1.17-bin.jar
    CLASSPATH=.:$CLASSPATH:/home/lsa/NetBeansProjects/Cadastro/dist/Cadastro.jar
    java -cp /home/lsa/Downloads/mysql-connector-java-5.1.17/mysql-connector-java-5.1.17-bin.jar:/home/lsa/NetBeansProjects/Cadastro/dist/Cadastro.jar cadastro.Cadastro
    but I keep getting this

    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 cadastro.dao.ConnectionDataBase.getConnection(Conn ectionDataBase.java:48)
    at cadastro.dao.GenericDao.<init>(GenericDao.java:19)
    at cadastro.dao.DadosDao.<init>(DadosDao.java:16)
    at cadastro.controller.DadosController.listaDados(Dad osController.java:65)
    at cadastro.Principal.<init>(Principal.java:33)
    at cadastro.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 cadastro.dao.ConnectionDataBase.getConnection(Conn ectionDataBase.java:26)
    ...5 more

  12. #32
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,387
    Rep Power
    25

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

    Can't connect to database
    Your code must be running.
    Now its a SQL usage error.

    If it works in the IDE then what is different?

  13. #33
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,001
    Rep Power
    20

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

    Is the IDE on the same box?
    Do you have the same driver jar file on the runtime classpath in the IDE?

  14. #34
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,512
    Blog Entries
    7
    Rep Power
    20

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

    Quote Originally Posted by Revoke View Post
    these errors

    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
    I have to repeat the question from reply #24 then ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

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

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

    Quote Originally Posted by JosAH View Post
    I have to repeat the question from reply #24 then ...

    kind regards,

    Jos
    I don't know how to check that

    Tolls

    I believe so

  16. #36
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,001
    Rep Power
    20

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

    I just told you how to check the manifest.
    Look in your jar file (the one with your code in it) and find the MANIFEST.MF file in the META-INF directory.
    Post its contents here.

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

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

    Quote Originally Posted by Tolls View Post
    I just told you how to check the manifest.
    Look in your jar file (the one with your code in it) and find the MANIFEST.MF file in the META-INF directory.
    Post its contents here.
    Sorry I'm really new to this :D

    Manifest-Version: 1.0

    Ant-Version: Apache Ant 1.8.2

    Created-By: 1.6.0_26-b03 (Sun Microsystems Inc.)

    Class-Path: lib/mysql-connector-java-5.1.17-bin.jar

    X-COMMENT: Main-Class will be added automatically by build

    Main-Class: cadastro.Cadastro

  18. #38
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,001
    Rep Power
    20

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

    Right.
    And when you ran the jar file, using java -jar <your jar file here> did you get the above exception?
    If so, then is there a lib directory there, containing the MySQL driver jar?

    If so...then we can ignore all the above stuff about class paths.

  19. #39
    Revoke is offline Member
    Join Date
    Aug 2011
    Posts
    25
    Rep Power
    0

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

    Quote Originally Posted by Tolls View Post
    Right.
    And when you ran the jar file, using java -jar <your jar file here> did you get the above exception?
    If so, then is there a lib directory there, containing the MySQL driver jar?

    If so...then we can ignore all the above stuff about class paths.
    Yes, I get the exception
    and yes the directory exists and it contains the driver jar

  20. #40
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,001
    Rep Power
    20

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

    OK.
    We've got somewhere (which we might have got to quicker if you'd not been eating exceptions).

    And running this in your IDE works?

    What IDE is it?

Page 2 of 3 FirstFirst 123 LastLast

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
  •