First We Have To Create A Database: Library
First We Have To Create A Database: Library
cmdSave.setEnabled(true);
try {
Class.forName("com.mysql.jdbc.Driver");
DriverManager.getConnection("jdbc:mysql://localhost:3306/library","root","
123456");
rs = stmt.executeQuery(SQL);
int pno = 1;
int PID=0;
while (rs.next()) {
PID = rs.getInt("pub_id");
pno++;
PID++;
pno = PID;
txtPno.setText(Integer.toString(pno));
txtPName.setFocusable(true);
con.close();
rs.close();
stmt.close();
} catch (Exception e) {
JOptionPane.showMessageDialog(this,e.getMessage());
e.printStackTrace();
} private void
cmdSaveActionPerformed(java.awt.event.ActionEvent evt) {
try {
Class.forName("com.mysql.jdbc.Driver");
DriverManager.getConnection("jdbc:mysql://localhost:3306/library","root","
123456");
ResultSet rs = null;
stmt = con.createStatement();
rs = stmt.executeQuery(SQL);
if(txtPh1.getText().length()!=10)
if(txtPh1.getText().contains("[0-9]"))
{
System.out.println("Invalid");
if(txtPh2.getText().length()!=10)
if(txtPh2.getText().contains("[0-9]"))
System.out.println("Invalid");
if (code == JOptionPane.YES_OPTION) {
}
con.close();
stmt.close();
rs.close();
cmdSave.setEnabled(false);
} catch (Exception e) {
JOptionPane.showMessageDialog(this, e.getMessage());
}
Now we have to MODIFY PUBLISHER DETAILS
We have to click on MODIFICATION button.
A new frame will open. On the left side of the frame all the
Publishers are shown.
Click on the Publisher which has to be Updated.
All the details will be shown.
try {
// Connect to MySQL database
// import java.sql.*;
// import javax.swing.JOptionPane;
Class.forName("com.mysql.jdbc.Driver");
DriverManager.getConnection("jdbc:mysql://localhost:3306/library","roo
t","123456");
ResultSet rs = null;
stmt = con.createStatement();
rs = stmt.executeQuery(SQL);
if(txtPh1.getText().length()!=10)
{
JOptionPane.showMessageDialog(this,"Incorrect Phone
Number!");
if(txtPh1.getText().contains("[0-9]"))
System.out.println("Invalid");
if(txtPh2.getText().length()!=10)
JOptionPane.showMessageDialog(this,"Incorrect Phone
Number!");
if(txtPh2.getText().contains("[0-9]"))
System.out.println("Invalid");
if (code == JOptionPane.YES_OPTION){
String strSQL = "Update publisher set pub_name
='"+(PubName)+"',pub_address = '"+(PubAdd)+"', pub_phone1 =
'"+(PubPh1)+"', pub_phone2 = '"+(PubPh2)+"', status = '"+(PStatus)+"'
where pub_id = " + (pno);
if (rowsEffected == 0)
else
JOptionPane.showMessageDialog(this,"Record modified");
} con.close();
stmt.close();
rs.close();
} catch (Exception e) {
JOptionPane.showMessageDialog(this, e.getMessage());
}
Now we have to DELETE PUBLISHER DETAILS
We have to click on DELETE button.
A new frame will open. On the left side of the frame all the
Publishers are shown.
Click on the Publisher which has to be Deleted.
All the details will be shown.
ResultSet rs = null;
String SQL = "SELECT * FROM Publisher";
try {
Class.forName("com.mysql.jdbc.Driver");
DriverManager.getConnection("jdbc:mysql://localhost:3306/library","roo
t","123456");
stmt = con.createStatement();
rs = stmt.executeQuery(SQL);
if (opt == JOptionPane.YES_OPTION)
try {
if (rowsEffected == 0)
else
JOptionPane.showMessageDialog(this,"Record Deleted");
txtPno.setText("");
txtPName.setText("");
txtPAdd.setText("");
txtPh1.setText("");
txtPh2.setText("");
txtStatus.setText("");
txtPno.setEditable(true);
} catch (Exception e) {
} catch (Exception e) {
JOptionPane.showMessageDialog(this, e.getMessage());
}