Page 2 of 2 FirstFirst 12
Results 21 to 24 of 24
  1. #21
    Eleeist is offline Member
    Join Date
    May 2011
    Posts
    84
    Rep Power
    0

    Default Re: JDBC mysql driver

    Oh... I just tought that it would run forever "holding" this connection until some condition causes it to stop. Well, then:

    Java Code:
    import java.sql.*;
    
    public class Database {
        
        public static void main(String[] args) throws Exception {
    
            Class.forName("com.mysql.jdbc.Driver");
    
            Connection con = DriverManager.getConnection("jdbc:mysql://localhost/mud", "myusername", "mypassword");  
            Statement stmt = con.createStatement();
            ResultSet rs = stmt.executeQuery("SELECT * FROM test_table");
    
            while (rs.next()) {
                String outputString = rs.getString("test_field");
                System.out.println(outputString);
            }
            
        }
        
    }
    Nothing :(.

  2. #22
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,351
    Blog Entries
    7
    Rep Power
    20

    Default Re: JDBC mysql driver

    If there was no output (no matter what) and if there were no errors, all I can guess is that table test_table is empty ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #23
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,817
    Rep Power
    19

    Default Re: JDBC mysql driver

    Quote Originally Posted by JosAH View Post
    There's another trick: the Java Runtime checks a special directory: JRE/lib/ext (JRE is where your Java Runtime is stored). .jar files in that directory don't have to be mentioned on the classpath environment variable; but be careful with it: it makes your jar (with all classes in it) available to each an every Java program you write and run (it can be a benefit though).

    kind regards,

    Jos
    You know how much I don't like this.
    You're doing it just to wind me up...:p
    It's a hack.

    Eleeist should be using the -cp flag...in the case of running the Test class directly (non-jarred):
    java -cp.;lib/*.jar Test

  4. #24
    Eleeist is offline Member
    Join Date
    May 2011
    Posts
    84
    Rep Power
    0

    Default Re: JDBC mysql driver

    I am embarassed to say that, but I indeed forgot to add any data to the database :D.

    Anyway, everything seems to work fine when I run Database.class. When the need comes to deploy the app and pack it into .jar, I will then try to resolve any issues related to it. Now I just want to get on with coding the app :).

    Thank you all so much for help!

    Have a nice day!

Page 2 of 2 FirstFirst 12

Similar Threads

  1. JDBC Problem - com.mysql.jdbc.Driver
    By icu222much in forum Advanced Java
    Replies: 5
    Last Post: 11-22-2011, 04:54 PM
  2. MySQL JDBC Driver ClassNotFound
    By Levian in forum New To Java
    Replies: 4
    Last Post: 06-17-2011, 09:37 AM
  3. ClassNotFoundException: com.mysql.jdbc.Driver
    By tBKwtWS in forum New To Java
    Replies: 9
    Last Post: 06-15-2011, 07:01 PM
  4. com.mysql.jdbc.Driver
    By uthpalaw in forum Eclipse
    Replies: 2
    Last Post: 10-14-2010, 05:09 AM
  5. Replies: 4
    Last Post: 03-31-2010, 12:08 PM

Posting Permissions

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