redi
redi
public tr() {
initComponents ();
createConnection();
}
/**
* This method is called from within the constructor to initialise the form.
* WARNING : Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@Suppres sWarnings (" unchecked")
// <editor-fold defaults tate=" collaps ed" des c="G enerated Code" >
private void initComponents() {
jLabel2.setText("jLabel2" );
jLabel4.setText("jLabel4" );
jLabel5.setText("jLabel5" );
jLabel1.setText("id" );
jLabel3.setText("name");
jLabel6.setText("department");
jLabel7.setText("age");
pack();
}/ / </editor-fold>
/**
* @param args the command line arguments
*/
public static void main(String args []) {
tr lo=new tr();
lo.createConnection();
}
void createConnection(){
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new tr().setVisible(true);
try{
// Load the JDBC drive
Class .forName("com.mys ql.cj.jdbc.Driver" );
Connection conn = DriverManager.getConnection(" jdbc:mysql:/ /localhost:3306/redi"," root" ,"root");
Statement stmt=conn.createStatement();
ResultSet rs=s tmt.executeQuery("s elect * from lab1" );
while(rs .next()){
String name=rs.getString(" id" );
String age=rs .getString(" name");
String n=rs .getString("department" );
String a=rs .getString("age" );
System.out.println(name);
System.out.println(" ");
System.out.println(age);
System.out.println(" ");
System.out.println(n);
System.out.print(" ");
System.out.println(a);
System.out.println("Database Connected Successfully." );
}
}
}
});
}