Advanced Search

Results 1 to 2 of 2

Thread: MySQL and Java

  1. #1
    Join Date
    Jul 2005
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default MySQL and Java

    Hello,
    I would like to access MySQL DB using java, but I don't know how. I found this:

    Code:
    import java.sql.*;
    class prueba { 
        public static void main (String[] args) { 
            try { 
    
                // Step 1: Load the JDBC driver. 
                Class.forName("com.mysql.jdbc.Driver"); 
    
                // Step 2: Establish the connection to the database. 
                //String url = "jdbc:msql://www.myserver.com:1114/contact_mgr"; 
                String url = "jdbc:msql://linuxfire:3306/sismosprueba"; 
                Connection conn = DriverManager.getConnection(url,"admsismos","rzambrano");  
    
            } catch (Exception e) { 
                System.err.println("Got an exception! "); 
                System.err.println(e.getMessage()); 
            } 
        } 
    }
    But it doesn't work. I think it is because of the driver, but I don't know which one I should use.
    Thanks
    Adriana

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,878
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    You have to have the jdbc/mysql.jar file provided with MySQL in your CLASSPATH.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

Bookmarks

Posting Permissions

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