#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2001
    Posts
    2
    Rep Power
    0

    Urgent Help Needed


    Hie thr,
    I am new towards Java Servlet Programming.
    I am trying to make a connection to mySql database so that I could insert/update/retrieve/delete database. The problem is, I donnu how to make the connection. Is there any files that I should import before making the connection?what other procedures/statement/coding should I put in order to make the connection?
    Help is really needed.
    Thanks.

    Randy
  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2001
    Location
    Rep. of Ireland
    Posts
    2
    Rep Power
    0
    This is the basis of it, you'll need to know the name of the MYSQL driver your host is using and change it accordingly.
    You'll also need to know the URL of the database, this should also be available from your host.
    You can plug this into any Servlet or JSP


    Firstly import java.sql.*; into your program, along with whatever else your importing.

    PHP Code:
    //Credentials for connecting to  database
    String url "jdbc:mysql://someurl";
    String user "username;
    String pass = "
    password";


    //Attempt connection & catch any errors that occur
    try
    {
     Class.forName( "
    org.gjt.mm.mysql.Driver" );//MySQL driver
     connection = DriverManager.getConnection(url, user, pass );
    }

    catch ( ClassNotFoundException cnfex )
    {
     System.err.println( "
    Failed to load JDBC/ODBC driver." );
     cnfex.printStackTrace();
     System.exit( 1 );  // terminate program
    }

    catch ( SQLException sqlex )
    {
     System.err.println( "
    Unable to connect" );
     sqlex.printStackTrace();

  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2000
    Posts
    4
    Rep Power
    0
    do a search on JDBC and you'll get lots of examples and how-to's you need to load in JDBC driver, make a connection and execute the SQL.

    Nick
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Location
    Indonesia
    Posts
    87
    Rep Power
    14
    hi.. i think you need MySQL JDBC driver ....
    You can download it from www.worldserver.com/mm.mysql/
    ** Science belongs to the world **

IMN logo majestic logo threadwatch logo seochat tools logo