Database Connectivity (JAVA & MySQL)

To create connection with database follow these 5 steps:

1.Register the driver class:
               Class.forName("com.mysql.jdbc.Driver");

2.Create Connection
               Connection con = DriverManager.getConnection(
                                             "jdbc:mysql://localhost/database_name",
                                             "user or root","password");

3.Create Statement
               PreparedStatement ps = con.prepareStatement("mysql query;");
                                                            OR
               Statement s = con.createStatment();

4.Execute Statement
               ps.executeUpdate();
                            OR
               s.executeQuery("mysql query");

5.Close Connection
               con.close();

Post a Comment

0 Comments