Java Database Connectivity with MySQL in NetBeans




This document demonstrates how to set up a connection to a MySQL database from the NetBeans IDE. Once connected, you can begin working with MySQL in …

source


28 responses to “Java Database Connectivity with MySQL in NetBeans”

  1. I wrote ur demo code as like as given in demo but it doesn't retrieve database result.
    It only says after run "Build Successful "
    But data of database Demo doesn't appear.
     Plz see my problem…
      package Demo;

    import java.sql.*;

    public class Demo {

        
        public static void main(String[] args)
        {
            try
            {
                String Query = "Select * from student where rollno = 2 " ;
            
            
       Class.forName("com.mysql.jdbc.Driver");
       
    Connection con = DriverManager.getConnection("jdbc:mysql://localhost/Demo","root","0");
            
            
            Statement st = con.createStatement();
            ResultSet rs = st.executeQuery(Query);
            rs.next();
            String name = rs.getString(2);
            System.out.println(name);
            con.close();
                    }           
        catch(Exception e ) 
        {
        }
        }
    }

  2. With all due respect on your efforts in explaining, @ 09:55 you say "here is derby and i used mysql… you can do whatever you want"… could you pls elaborate on that?

    If I am not wrong, you should be choosing the mysql driver name just above the host.

    The reason i was here is that i could not get connected to mysql server from netbeans where as from mysql workbench i could. can help me?

Leave a Reply