Results 1 to 7 of 7
  1. #1
    soundlord is offline Member
    Join Date
    Mar 2011
    Posts
    14
    Rep Power
    0

    Default [MySQL Connector 5.1.6] Issue with Driver.connect()

    Greetings !!

    I'm trying those instructions:

    Java Code:
    Properties PropConnection=new Properties();
    PropConnection.setProperty("user", "**********");                     
    PropConnection.setProperty("password","**********");             
    conMySQL=(com.mysql.jdbc.Connection)DriverMySQL.connect("jdbc:mysql://localhost/test",PropConnection);
    And once at the connect() I got this message

    Java Code:
    "Communications link failure
    
    Last packet sent to the server was 10 ms ago."
    I really have no idea how to fix this issue.
    If someone has ever had such experience can you give me informations to solve it ?

    Thank you in advance !

  2. #2
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    7

    Default

    What is DriverMySQL? Are you using Connector J? See
    Trail: JDBC(TM) Database Access (The Java™ Tutorials)
    and
    MySQL :: MySQL Connectors

  3. #3
    soundlord is offline Member
    Join Date
    Mar 2011
    Posts
    14
    Rep Power
    0

    Default A+pplet

    Thank you !

    The DriverMySQL is an object instanciated from class com.mysql.jdbc.Driver.
    As I use an Applet I can't use the usual DriverManager class because this code I used in "simple" client/server applications (not an Applet) won't work.

    Java Code:
    Class.forName("com.mysql.jdbc.Driver").newInstance();
    connexionToDB=DriverManager.getConnection(dburl,username,password);
    I asked many times to the java users (maybe my questions weren't sufficiently precise) to obtain a workaround to pass thru the fact that Class.forName won't work and I finally found a way to do it, but it only works on my other computer ^^

    Here I'm sure that this is possible to connect an Applet to a MySQL server because it works on another computer, but I really don't know why I got this exception with this computer.

    The only thing that is different between the two computers are:

    The OS (11.4 64bits vs 11.3 32bits)
    The version of the connector (5.1.13 vs 5.1.6)
    The version of the NetBeans IDE used (7.0 vs 6.9.1)

    That's all I have for now...
    I'll dig and keep on searching...

  4. #4
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    7

    Default

    As I use an Applet I can't use the usual DriverManager class because this code I used in "simple" client/server applications (not an Applet) won't work
    Describe 'won't work'...I'm guessing you receive a security exception?

    I'm surprised either worked on any computer. On the computer that worked, does your database reside on that machine as well? Either way, you need to sign your applet. Suggest you read the following:
    What Applets Can and Cannot Do (The Java™ Tutorials > Deployment > Java Applets)
    and I recommend you follow the standard syntax described in the link above for accessing a database connection

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

    Default

    Class.forName won't work
    Was the class you were trying to load on the classpath so the JVM could find and load it?

  6. #6
    soundlord is offline Member
    Join Date
    Mar 2011
    Posts
    14
    Rep Power
    0

    Default

    Yes but it was before I used the IDE and I discovered in my journey that it is possible to insert a library (for example mysql connector) and then it copies it to the namespace, thanks to this feature, (apparently, but I didn't tested it deeper) this is maybe possible to use the forname() to load the library. Here, I found another way that works on my SuSE 11.4 system (I'm testing on two different computers, one in 11.4 and the second in 11.3).

    I'm trying to have explainations about the exception launched (related to communication links -- ???)
    and from that point I should solve the issue (I'll try at all).

    I got crazy the first time I wrote an Applet with this forname() method that never worked so I was forced to write a "proxy" to talk to the database and the Applet thru simple socket system... that was very disappointing.

    Java is the solution I found to ensure perfect compatibility when using a browser even you are running windows, mac or linux... that's the challenge: wrote a simple Applet to help all my colleagues to fill the student's scores anywhere they are (from home particulary).

    If you find any informations don't hesitate to share it with me, I'm thirsty of java knowledge

  7. #7
    soundlord is offline Member
    Join Date
    Mar 2011
    Posts
    14
    Rep Power
    0

    Default

    @dowhile

    Thank you for your reply...

    English is not my native tongue, and I read again the sentence and I understand why you asked me to give more precisions...
    All my apologizes ^^

    The first time I wrote an Applet I tried the different "recipes" I read from books and tutorials to make it discuss with a database like MySQL.
    Those "recipes" adviced to use the DriverManager class and use forname() method as described in my previous post (this one) and it worked for a simple application (console) with a database located on the same computer.
    The next step was to use the same "framework" but anywhere I was on the planet, so I decided to write an Applet.
    But I was confronted to the fact that even if java.policy was changed to let an Applet use the 3306 port, there was no way to load a class from within the Applet.
    At this point I wrote a "proxy" to let the Applet send the request to a daemon which was expected to "relay" the requests from the Applet to the MySQL server and then "upward" the results to the Applet.
    That was quite a bad experience because it was the first time I was forced to do so and I'm not an expert in Java programming ^^

    I dig the language reference and tried another solution that worked on my SuSE 11.4 computer but not with my SuSE 11.3 (I'm testing on two different computers).
    Right now, for testing, the databases are replicated on both computers and used locally, but the idea is to use the databases remotly from anywhere.

    I will read the link even if I have the impression I already did that ^^

    Thank you...
    Last edited by soundlord; 07-02-2011 at 01:38 AM.

Similar Threads

  1. JDBC with Connector/J with MySQL
    By nmvp in forum JDBC
    Replies: 2
    Last Post: 02-16-2011, 06:30 AM
  2. Connector J with Eclipse and MySQL 5.0.x
    By int80 in forum Eclipse
    Replies: 11
    Last Post: 05-31-2010, 09:32 AM
  3. Oracle Connect thru register driver
    By chyrl in forum JDBC
    Replies: 5
    Last Post: 05-11-2010, 03:45 PM
  4. mysql connector to java
    By sweet angle in forum JDBC
    Replies: 4
    Last Post: 10-20-2008, 06:33 AM
  5. MySQL connector selection
    By Ms.Ranjan in forum JDBC
    Replies: 3
    Last Post: 06-23-2008, 05:27 PM

Tags for this Thread

Posting Permissions

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