Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

how to connect a java application to mysql database

843859Apr 7 2009 — edited Apr 7 2009
Hi frnds..

I have googled it and done research but unable to connect to mysql.please help me out and tell me how to connect.

I have down loaded my sql and changed the port to 8001 and given some user name and pass word

and have written this code
 import java.sql.*;

   public class connect
   {
       public static void main (String[] args)
       {
          

           try
           {
               Class.forName("com.mysql.jdbc.Driver");
               Connection con = DriverManager.getConnection ("jdbc:mysql://localhost/test", "root", "konh");
               System.out.println ("Database connection established");
           }
           catch (Exception e)
           {
               System.out.println ("Exception raised trying again");
           }
           
       }
   }
Edited by: maganti on Apr 7, 2009 3:10 AM
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 5 2009
Added on Apr 7 2009
12 comments
329 views