How to connect to mysql through JAVA? - PHP

This is a discussion on How to connect to mysql through JAVA? - PHP ; Hi, What is the command to connect to mysql through java. Thanks and Regards Balaji...

+ Reply to Thread
Results 1 to 4 of 4

How to connect to mysql through JAVA?

  1. Default How to connect to mysql through JAVA?

    Hi,
    What is the command to connect to mysql through java.

    Thanks and Regards
    Balaji



  2. Default Re: How to connect to mysql through JAVA?

    Try checking the sun documentation...java.sun.com
    or the mysql documentation...

    Ray Hunter


    "Balaji Ankem" <balaji.ankem@wipro.com> wrote in message
    news:4192544610.4461041925@wipro.com...
    > Hi,
    > What is the command to connect to mysql through java.
    >
    > Thanks and Regards
    > Balaji
    >
    >




  3. Default RE: [PHP] Re: How to connect to mysql through JAVA?


    Sourceforge MySQL JDBC driver
    http://mmmysql.sourceforge.net/

    maybe this code frag will be helpful...

    String connectionURL = "jdbc:mysql://centauri.sbs:3306/dbname";
    Connection conn = null;
    Statement statement = null;
    ResultSet rset = null;
    try {
    Class.forName("org.gjt.mm.mysql.Driver").newInstance();
    conn = DriverManager.getConnection(connectionURL,"servlet","password");
    statement = conn.createStatement(
    ResultSet.TYPE_SCROLL_SENSITIVE,
    ResultSet.CONCUR_UPDATABLE);
    rset = statement.executeQuery(
    "SELECT * FROM BROWSER WHERE sessionID='"
    + request.getParameter("session_id") +"'");

    .. now use rset
    } // try
    catch( ClassNotFoundException e ) {
    PrintWriter pw = new PrintWriter(out, true);
    pw.println("Couldn't find the mm database driver: "
    + e.getMessage());
    }
    catch( InstantiationException e ) {
    PrintWriter pw = new PrintWriter(out, true);
    pw.println(e.getMessage());
    }
    catch( IllegalAccessException e ) {
    PrintWriter pw = new PrintWriter(out, true);
    pw.println(e.getMessage());
    }
    catch( SQLException e ) {
    PrintWriter pw = new PrintWriter(out, true);
    pw.println("SQL Problem: " + e.getMessage());
    pw.println("SQL State: " + e.getSQLState());
    pw.println("Vendor Error: " + e.getErrorCode());
    }
    finally {
    try {
    if ( conn != null )
    conn.close();
    }
    catch( SQLException e ) {
    PrintWriter pw = new PrintWriter(out, true);
    pw.println(e.getMessage());
    }
    }


  4. Default Re: [PHP] Re: How to connect to mysql through JAVA?

    The last post is using the MySQL JDBC from a Java Server Page in a servlet
    environment. I never tried to run this from Java imbedded in a PHP script.
    You would have to remove the exception handling, at least.

    I dispatch a Java Server Page from my php script (write to a socket), do
    some java stuff there involving my MySQL db, and return the output to my php
    script (read from socket).

    I can send more details on this if you're interested.

    Rich



+ Reply to Thread