0% found this document useful (0 votes)
20 views1 page

redi

impoert

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 PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views1 page

redi

impoert

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 PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 1

package itr;

import java.s ql.Connection;


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

public class tr extends javax.s wing.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.
*/
@Suppres sWarnings (" unchecked")
// <editor-fold defaults tate=" collaps ed" des c="G enerated 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.s wing.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.WindowCons tants .EXIT_ON_CLOSE);

jLabel1.setText("id" );

jLabel3.setText("name");

jLabel6.setText("department");

jLabel7.setText("age");

jButton1.s etText(" Regiter" );


jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});

javax.s wing.GroupLayout layout = new javax.s wing.G roupLayout(getContentPane());


getContentPane().s etLayout(layout);
layout.s etHorizontalG roup(
layout.createParallelGroup(javax.s wing.G roupLayout.Alignment.LEADING )
.addG roup(layout.createSequentialG roup()
.addG roup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING )
.addG roup(layout.createSequentialGroup()
.addG ap(173, 173, 173)
.addComponent(jButton1))
.addG roup(layout.createSequentialGroup()
.addG ap(53, 53, 53)
.addG roup(layout.createParallelGroup(javax.s wing.G roupLayout.Alignment.TRAILING )
.addComponent(jLabel7)
.addComponent(jLabel6)
.addComponent(jLabel3)
.addComponent(jLabel1))
.addG ap(91, 91, 91)
.addG roup(layout.createParallelGroup(javax.s wing.G roupLayout.Alignment.LEADING , false)
.addComponent(t3)
.addComponent(t1, javax.s wing.GroupLayout.DEFAULT_SIZE, 152, Short.MAX_VALUE)
.addComponent(t2)
.addComponent(t4))))
.addContainerG ap(180, Short.MAX_VALUE))
);
layout.s etVerticalG roup(
layout.createParallelGroup(javax.s wing.G roupLayout.Alignment.LEADING )
.addG roup(layout.createSequentialG roup()
.addG ap(43, 43, 43)
.addG roup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.TRAILING )
.addG roup(layout.createSequentialGroup()
.addG roup(layout.createParallelGroup(javax.s wing.G roupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(t1, javax.s wing.GroupLayout.PREFERRED_SIZE, javax.swing.G roupLayout.DEFAULT_SIZE, javax.swing.G roupLayout.PREFERRED_SIZE))
.addG ap(18, 18, 18)
.addComponent(jLabel3, javax.s wing.G roupLayout.PREFERRED_SIZE, 33, javax.s wing.G roupLayout.PREFERRED_SIZE))
.addComponent(t2, javax.s wing.G roupLayout.PREFERRED_SIZE, javax.s wing.GroupLayout.DEFAULT_SIZE, javax.swing.G roupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addG roup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING )
.addG roup(layout.createSequentialGroup()
.addComponent(jLabel6)
.addG ap(36, 36, 36))
.addG roup(javax.s wing.GroupLayout.Alignment.TRAILING , layout.createSequentialG roup()
.addComponent(t3, javax.s wing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.G roupLayout.PREFERRED_SIZE)
.addG ap(18, 18, 18)))
.addG roup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.BASELINE)
.addComponent(jLabel7)
.addComponent(t4, javax.s wing.G roupLayout.PREFERRED_SIZE, javax.s wing.GroupLayout.DEFAULT_SIZE, javax.swing.G roupLayout.PREFERRED_SIZE))
.addG ap(54, 54, 54)
.addComponent(jButton1)
.addContainerG ap(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.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." );
}

} catch(Class NotFoundException ex){


Logger.getLogger(tr.clas s.getName()).log(Level.SEVERE, null, ex);
} catch(SQLException ex){
Logger.getLogger(tr.clas s.getName()).log(Level.SEVERE, null, ex);

}
}
});
}

// Variables declaration - do not modify


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

You might also like