Guyyoooo
Guyyoooo
package library;
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;
lo.createConnection();
void createConnection(){
try{
Class.forName("com.mysql.cj.jdbc.Driver");
Connection conn =
DriverManager.getConnection("jdbc:mysql://localhost:3306/libary","root","root");
Statement stmt=conn.createStatement();
while(rs.next()){
String name=rs.getString("id");
String age=rs.getString("name");
String n=rs.getString("book");
String a=rs.getString("department");
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);
} catch(ClassNotFoundException ex){
} catch(SQLException ex){
/*
*/
package library;
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;
Connection conn;
/**
*/
public lib() {
initComponents();
CreateConnection();
void CreateConnection(){
try{
Class.forName("com.mysql.cj.jdbc.Driver");
conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/libary","root","root");
Logger.getLogger(lib.class.getName()).log(Level.SEVERE, null,ex);
}
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
*/
@SuppressWarnings("unchecked")
t1 = new javax.swing.JTextField();
t2 = new javax.swing.JTextField();
t3 = new javax.swing.JTextField();
t4 = new javax.swing.JTextField();
b1 = new javax.swing.JButton();
jLabel1.setText("ID");
jLabel2.setText("Name");
jLabel3.setText("Book");
jLabel4.setText("Department");
b1.setText("Save");
b1.addActionListener(new java.awt.event.ActionListener() {
b1ActionPerformed(evt);
});
jButton2.setText("Cancel");
jTextArea1.setColumns(20);
jTextArea1.setRows(5);
jScrollPane1.setViewportView(jTextArea1);
jRadioButton2.setText("Female");
jRadioButton3.setText("Male");
jRadioButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jRadioButton3ActionPerformed(evt);
});
jLabel5.setText("Gender");
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(b1)
.addComponent(jButton2))
.addGroup(layout.createSequentialGroup()
.addContainerGap(141, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel2)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 60,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel3)
.addComponent(jLabel4))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(t1)
.addComponent(t2)
.addComponent(t3)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jRadioButton2, javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jRadioButton3, javax.swing.GroupLayout.Alignment.TRAILING))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jRadioButton3)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(t1, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jRadioButton2)))
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel5)))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(t2, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jLabel3)
.addComponent(t3, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel4)
.addComponent(t4, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(b1)
.addComponent(jButton2))
.addGap(58, 58, 58))
);
pack();
}// </editor-fold>
try{
String id =t1.getText();
stmt.execute(query);
stmt.close();
/**
*/
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
*/
try {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
java.util.logging.Logger.getLogger(lib.class.getName()).log(java.util.logging.Level.SEVERE, null,
ex);
java.util.logging.Logger.getLogger(lib.class.getName()).log(java.util.logging.Level.SEVERE, null,
ex);
java.util.logging.Logger.getLogger(lib.class.getName()).log(java.util.logging.Level.SEVERE, null,
ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(lib.class.getName()).log(java.util.logging.Level.SEVERE, null,
ex);
//</editor-fold>
java.awt.EventQueue.invokeLater(new Runnable() {
new lib().setVisible(true);
});