Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2003
    Posts
    2

    Unanswered: MySQL Connector/J

    how do i connection MySQL using MySQL Connector/J in Java?

  2. #2
    Join Date
    Jan 2003
    Location
    Paris, France
    Posts
    320

    Re: MySQL Connector/J

    Originally posted by blackie
    how do i connection MySQL using MySQL Connector/J in Java?
    what do you need

    how to create a connection ?

    how to install the driver ?
    Olivier Miossec
    --
    http://www.lasso-developpeur.net/
    --

  3. #3
    Join Date
    Mar 2003
    Posts
    2

    Re: MySQL Connector/J

    Originally posted by omiossec
    what do you need

    how to create a connection ?

    how to install the driver ?
    i need to know how is it been used in a sense the String used to connect the MySQL...

  4. #4
    Join Date
    Apr 2003
    Location
    New York City
    Posts
    2

    Re: MySQL Connector/J

    Originally posted by blackie
    i need to know how is it been used in a sense the String used to connect the MySQL...
    I just fought with this for awhile.
    Give this sample code a try:

    import java.sql.*;
    import java.util.*;

    public class CheckDriverManager {

    public static void main(String[] args) {
    String driverName = "com.mysql.jdbc.Driver";
    Connection conn = null;

    //Put in your databasename here
    String databaseURL = "jdbc:mysql://localhost/databasename";

    //Put in your username and password here
    String username = "someuser";
    String password = "somepassword";

    // Verify that the driver class exists.
    try {
    Class.forName(driverName);
    System.out.println("Did Class.forName()"); //LOGGER
    } catch (Exception e) {
    e.printStackTrace();
    System.out.println("Driver could not be found.");
    }

    // Get a connection.
    try {
    conn = DriverManager.getConnection(databaseURL, username, password);
    System.out.println("Did getConnection()"); //LOGGER

    Statement stat = conn.createStatement();

    //Put in your own table name here.
    ResultSet result = stat.executeQuery("SELECT * FROM tablename");
    result.next();
    System.out.println(result.getString(1));

    stat.close();
    conn.close();

    } catch (SQLException sqle) {
    sqle.printStackTrace();
    System.out.println("Could not get connection."); //LOGGER
    }
    }
    }

Posting Permissions

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