0% found this document useful (0 votes)
14 views4 pages

redi

important

Uploaded by

kenabadane9299
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views4 pages

redi

important

Uploaded by

kenabadane9299
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

package itr;

import java.sql.Connection;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Logger;
import java.util.logging.Level;

public class tr extends javax.swing.JFrame {


Connection conn;

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.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">

private void initComponents() {

jLabel2 = new javax.swing.JLabel();


jLabel4 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
jLabel1 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jLabel6 = new javax.swing.JLabel();
jLabel7 = new javax.swing.JLabel();
jButton1 = new javax.swing.JButton();
t1 = new javax.swing.JTextField();
t2 = new javax.swing.JTextField();
t3 = new javax.swing.JTextField();
t4 = new javax.swing.JTextField();

jLabel2.setText("jLabel2");

jLabel4.setText("jLabel4");

jLabel5.setText("jLabel5");

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

jLabel1.setText("id");

jLabel3.setText("name");

jLabel6.setText("department");

jLabel7.setText("age");
jButton1.setText("Regiter");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});

javax.swing.GroupLayout layout = new


javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignm
ent.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(173, 173, 173)
.addComponent(jButton1))
.addGroup(layout.createSequentialGroup()
.addGap(53, 53, 53)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayou
t.Alignment.TRAILING)
.addComponent(jLabel7)
.addComponent(jLabel6)
.addComponent(jLabel3)
.addComponent(jLabel1))
.addGap(91, 91, 91)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayou
t.Alignment.LEADING, false)
.addComponent(t3)
.addComponent(t1, javax.swing.GroupLayout.DEFAULT_SIZE,
152, Short.MAX_VALUE)
.addComponent(t2)
.addComponent(t4))))
.addContainerGap(180, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(43, 43, 43)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignm
ent.TRAILING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayou
t.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(t1,
javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addComponent(jLabel3,
javax.swing.GroupLayout.PREFERRED_SIZE, 33,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(t2, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELAT
ED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignm
ent.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel6)
.addGap(36, 36, 36))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
layout.createSequentialGroup()
.addComponent(t3, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignm
ent.BASELINE)
.addComponent(jLabel7)
.addComponent(t4, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(54, 54, 54)
.addComponent(jButton1)
.addContainerGap(104, Short.MAX_VALUE))
);

pack();
}// </editor-fold>

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:


}

/**
* @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.mysql.cj.jdbc.Driver");
Connection conn =
DriverManager.getConnection("jdbc:mysql://localhost:3306/redi","root","root");
Statement stmt=conn.createStatement();
ResultSet rs=stmt.executeQuery("select * 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.");
}
} catch(ClassNotFoundException ex){
Logger.getLogger(tr.class.getName()).log(Level.SEVERE, null, ex);
} catch(SQLException ex){
Logger.getLogger(tr.class.getName()).log(Level.SEVERE, null, ex);

}
}
});
}

// Variables declaration - do not modify


private javax.swing.JButton jButton1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel jLabel7;
private javax.swing.JTextField t1;
private javax.swing.JTextField t2;
private javax.swing.JTextField t3;
private javax.swing.JTextField t4;
// End of variables declaration
}

You might also like