Java and MySQL - How To Connect Java To MySQL And Dsiplay Data In NetBeans

Java and MySQL - How To Connect Java To MySQL And Dsiplay Data In NetBeans

__________________________________________________________________________

In This Java Tutorial We Will See How To Connect Java To MySQL DataBase Using NetBeans.




Project Source Code:


downloads connector:  http://dev.mysql.com/downloads/connector/j

package javadb_001;
import java.sql.*;

public class JavaDB_001 {

    public static void main(String[] args) {
     
     try{
         Connection con = DriverManager.getConnection("jdbc:mysql://localhost/test_db","root","");
         Statement st = con.createStatement();
         ResultSet rs = st.executeQuery("select * from users");
         while(rs.next())
         {
             System.out.println(rs.getString(1));
             System.out.println(rs.getString(2));
             System.out.println(rs.getString(3));
             System.out.println(rs.getString(4));
             System.out.println("----------------------");
         }
         
     }catch(Exception e)
     {
         System.out.println(e.getMessage());
     }
    }
}

Share this

Related Posts

Previous
Next Post »