KEMBAR78
Xii Project | PDF | Information Technology Management | Computer Data
0% found this document useful (0 votes)
45 views40 pages

Xii Project

12 JAVA PROJECT

Uploaded by

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

Xii Project

12 JAVA PROJECT

Uploaded by

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

//Main.

java
public class Main {

public static void main(String[] args) {

// TODO code application logic here

new TPassword().setVisible(true);

// TPassword.java
private void btnClickActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:

String PassW="SST";

String p= new String(txtPass.getPassword());

if(p.equals(PassW))

{new StuMain().setVisible(true);

this.setVisible(false);

else

{ JOptionPane.showMessageDialog(this, "Wrong Password");

System.exit(0);

}
// StuMain.java
private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:

new TSave().setVisible(true);

this.setVisible(false);

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

// TODO add your handling code here:

System.exit(0);

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

// TODO add your handling code here:

new TNavigate().setVisible(true);

this.setVisible(false);

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

// TODO add your handling code here:

new DSave().setVisible(true);

this.setVisible(false);

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

// TODO add your handling code here:

new TUpdate().setVisible(true);
this.setVisible(false);

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

// TODO add your handling code here:

new TDelete().setVisible(true);

this.setVisible(false);

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

// TODO add your handling code here:

new TReport().setVisible(true);

this.setVisible(false);

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

// TODO add your handling code here:

new DNavigate().setVisible(true);

this.setVisible(false);

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

// TODO add your handling code here:

new DUpdate().setVisible(true);

this.setVisible(false);

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


// TODO add your handling code here:

new DDelete().setVisible(true);

this.setVisible(false);

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

// TODO add your handling code here:

new DReport().setVisible(true);

this.setVisible(false);

}
//TSave.java

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

// TODO add your handling code here:

Statement stmt = null;

ResultSet rs = null;

try

Class.forName("com.mysql.jdbc.Driver");

Connection con=
(Connection)DriverManager.getConnection("jdbc:mysql://localhost:3306/school", "root", "aps");

String SQL = "select*from teacher";

stmt = (Statement) con.createStatement();

rs = stmt.executeQuery(SQL);

while (rs.next()){

System.out.println(rs.getString("tname"));

String ntNo = txtTNo.getText();

String name =txtTName.getText();

double nSalary = Double.parseDouble(txtTsalary.getText());

String ndept = txtTdeptno.getText();

String strSQL = "INSERT INTO


teacher(T_No,T_Name,Salary,Dept_No)VALUES('"+(ntNo)+"','"+(name)+"',"+(nSalary)+",'"+(
ndept)+"')";
System.out.print("Insert new record:");

int rowsEffected= stmt.executeUpdate(strSQL);

System.out.println(rowsEffected + "rows effected");

catch (Exception e){

JOptionPane.showMessageDialog(this,e.getMessage());

e.printStackTrace();

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

// TODO add your handling code here:

new StuMain().setVisible(true);

this.setVisible(false);

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

// TODO add your handling code here:

txtTNo.setText("");

txtTName.setText("");

txtTsalary.setText("");

txtTdeptno.setText("");

}
//DSave.java

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

// TODO add your handling code here:

Statement stmt = null;

ResultSet rs = null;

try

Class.forName("com.mysql.jdbc.Driver");

Connection con=
(Connection)DriverManager.getConnection("jdbc:mysql://localhost:3306/school", "root", "aps");

String SQL = "select * from DEPARTMENT";

stmt = (Statement) con.createStatement();

rs = stmt.executeQuery(SQL);

while (rs.next()){

System.out.println(rs.getString("tname"));

String DNo = txtdno.getText();

String DName =txtdname.getText();

String strSQL = "INSERT INTO Department(dept_no,


deptname)VALUES('"+(DNo)+"','"+(DName)+"')";

System.out.print("Insert new record:");

int rowsEffected= stmt.executeUpdate(strSQL);

System.out.println(rowsEffected + "rows effected");

catch (Exception e){


JOptionPane.showMessageDialog(this,e.getMessage());

e.printStackTrace();

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

// TODO add your handling code here:

new StuMain().setVisible(true);

this.setVisible(false);

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

// TODO add your handling code here:

txtdno.setText("");

txtdname.setText("");

}
//TNavigate.java

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

// TODO add your handling code here:

Statement stmt = null;

ResultSet rs = null;

try

Class.forName("com.mysql.jdbc.Driver");

Connection con=
(Connection)DriverManager.getConnection("jdbc:mysql://localhost:3306/school", "root", "aps");

String SQL = "select*from teacher";

stmt = (Statement) con.createStatement();

rs = stmt.executeQuery(SQL);

rs.first();

String ntNo = rs.getString("TNo");

String name = rs.getString("TName");

float nSalary = rs.getFloat("Salary");

String ndept = rs.getString("Dept_No");

txtTNo.setText(ntNo);

txtTName.setText(name);

txtTsalary.setText(""+ nSalary);

txtTdeptno.setText(ndept);
btnPrev.setEnabled(false);

btnLast.setEnabled(true);

btnNext.setEnabled(true);

catch (Exception e){

JOptionPane.showMessageDialog(this,e.getMessage());

e.printStackTrace();

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

// TODO add your handling code here:

Statement stmt = null;

ResultSet rs = null;

try

Class.forName("com.mysql.jdbc.Driver");

Connection con=
(Connection)DriverManager.getConnection("jdbc:mysql://localhost:3306/school", "root", "aps");

String SQL = "select * from teacher";

if(rs.next())//if next position is a true record

String ntNo = rs.getString("T_No");

String name = rs.getString("T_Name");

float nSalary = rs.getFloat("Salary");


String ndept = rs.getString("Dept_No");

txtTNo.setText(ntNo);

txtTName.setText(name);

txtTsalary.setText(""+ nSalary);

txtTdeptno.setText(ndept);

btnPrev.setEnabled(true);

btnLast.setEnabled(true);

btnFirst.setEnabled(true);

else{

JOptionPane.showMessageDialog(this,"You are at last record position","Teacher",0);

} catch (Exception e){

JOptionPane.showMessageDialog(this,e.getMessage());

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

// TODO add your handling code here:

Statement stmt = null;

ResultSet rs = null;

try

Class.forName("com.mysql.jdbc.Driver");
Connection con=
(Connection)DriverManager.getConnection("jdbc:mysql://localhost:3306/school", "root", "aps");

//Whenever the first position is trueIf next position

//is a true record

if(rs.previous()){

String ntNo = rs.getString("T_No");

String name = rs.getString("T_Name");

float nSalary = rs.getFloat("Salary");

String ndept = rs.getString("Dept_No");

txtTNo.setText(ntNo);

txtTName.setText(name);

txtTsalary.setText(""+ nSalary);

txtTdeptno.setText(ndept);

btnNext.setEnabled(true);

btnLast.setEnabled(true);

btnFirst.setEnabled(true);

else{

JOptionPane.showMessageDialog(this,"You are at last record position","Teacher",0);

} catch (Exception e){

JOptionPane.showMessageDialog(this,e.getMessage());

}
private void btnLastActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:

Statement stmt = null;

ResultSet rs = null;

try

Class.forName("com.mysql.jdbc.Driver");

Connection con=
(Connection)DriverManager.getConnection("jdbc:mysql://localhost:3306/school", "root", "aps");

//Whenever the first position is trueIf next position

//is a true record

if(rs.previous()){

String ntNo = rs.getString("T_No");

String name = rs.getString("T_Name");

float nSalary = rs.getFloat("Salary");

String ndept = rs.getString("Dept_No");

txtTNo.setText(ntNo);

txtTName.setText(name);

txtTsalary.setText(""+ nSalary);

txtTdeptno.setText(ndept);

btnNext.setEnabled(false);

btnPrev.setEnabled(true);

btnFirst.setEnabled(false);

else{
JOptionPane.showMessageDialog(this,"You are at last record position","Teacher",0);

} catch (Exception e){

JOptionPane.showMessageDialog(this,e.getMessage());

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

// TODO add your handling code here:

txtTNo.setText("");

txtTName.setText("");

txtTsalary.setText("");

txtTdeptno.setText("");

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

// TODO add your handling code here:

new StuMain().setVisible(true);

this.setVisible(false);

}
//DNavigate.java

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

// TODO add your handling code here:

Statement stmt = null;

ResultSet rs = null;

try

Class.forName("com.mysql.jdbc.Driver");

Connection con=
(Connection)DriverManager.getConnection("jdbc:mysql://localhost:3306/school", "root", "aps");

//Whenever the first position is trueIf next position

//is a true record

if(rs.previous())

String DNo = rs.getString("dept_no");

String DName = rs.getString("deptname");

txtdno.setText(DNo);

txtdname.setText(DName);

btnMNext.setEnabled(false);

btnMPrevious.setEnabled(true);

btnMFirst.setEnabled(false);

else{
JOptionPane.showMessageDialog(this,"You are at last record
position","DEPARTMENT",0);

} catch (Exception e){

JOptionPane.showMessageDialog(this,e.getMessage());

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

// TODO add your handling code here:

Statement stmt = null;

ResultSet rs = null;

try

Class.forName("com.mysql.jdbc.Driver");

Connection con=
(Connection)DriverManager.getConnection("jdbc:mysql://localhost:3306/school", "root", "aps");

String SQL = "select*from DEPARTMENT";

stmt = (Statement) con.createStatement();

rs = stmt.executeQuery(SQL);

rs.first();

String Dno = rs.getString("dept_no");

String Dname = rs.getString("deptname");

txtdno.setText(Dno);

txtdname.setText(Dname);
btnMPrevious.setEnabled(false);

btnMLast.setEnabled(true);

btnMNext.setEnabled(true);

catch (Exception e){

JOptionPane.showMessageDialog(this,e.getMessage());

e.printStackTrace();

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

// TODO add your handling code here:

Statement stmt = null;

ResultSet rs = null;

try

Class.forName("com.mysql.jdbc.Driver");

Connection con=
(Connection)DriverManager.getConnection("jdbc:mysql://localhost:3306/school", "root", "aps");

String SQL = "select * from DEPARTMENT";

if(rs.next())//if next position is a true record

String Dno = rs.getString("dept_no");

String Dname = rs.getString("deptname");

txtdno.setText(Dno);
txtdname.setText(Dname);

btnMPrevious.setEnabled(true);

btnMLast.setEnabled(true);

btnMFirst.setEnabled(true);

else{

JOptionPane.showMessageDialog(this,"You are at last record


position","DEPARTMENT",0);

} catch (Exception e){

JOptionPane.showMessageDialog(this,e.getMessage());

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

// TODO add your handling code here:

Statement stmt = null;

ResultSet rs = null;

try

Class.forName("com.mysql.jdbc.Driver");

Connection con=
(Connection)DriverManager.getConnection("jdbc:mysql://localhost:3306/school", "root", "aps");

//Whenever the first position is trueIf next position

//is a true record

if(rs.previous())
{

String nDNO = rs.getString("dept_no");

String nDName = rs.getString("deptname");

txtdno.setText(nDNO);

txtdname.setText(nDName);

btnMNext.setEnabled(true);

btnMLast.setEnabled(true);

btnMFirst.setEnabled(true);

else{

JOptionPane.showMessageDialog(this,"You are at last record


position","DEPARTMENT",0);

} catch (Exception e){

JOptionPane.showMessageDialog(this,e.getMessage());

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

// TODO add your handling code here:

txtdno.setText("");

txtdname.setText("");

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


// TODO add your handling code here:

new StuMain().setVisible(true);

this.setVisible(false);

}
//DUpdate.java

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

// TODO add your handling code here:

try

Class.forName("com.mysql.jdbc.Driver");

Connection con= (Connection)


DriverManager.getConnection("jdbc:mysql://localhost:3306/school", "root", "aps");

Statement stmt= con.createStatement();

String DNo = txtdno.getText();

String DName =txtdname.getText();

String strSQL = "Update Department set dept_no= '"+(DNo)+"',


deptname='"+(DName)+"'";

int rowsEffected=stmt.executeUpdate(strSQL);

if (rowsEffected== 0)

JOptionPane.showMessageDialog(this, "Record Updated");

else

JOptionPane.showMessageDialog(this, "Record does not exist");

catch (Exception e){

JOptionPane.showMessageDialog(this,e.getMessage());

e.printStackTrace();

}
private void btnBTMActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:

new StuMain().setVisible(true);

this.setVisible(false);

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

// TODO add your handling code here:

DefaultListModel dModel= (DefaultListModel)jList1.getModel();

txtdno.enableInputMethods(false);

try

Class.forName("com.mysql.jdbc.Driver");

Connection con= (Connection)


DriverManager.getConnection("jdbc:mysql://localhost:3306/school", "root", "aps");

String SQL= "SELECT * from Department";

Statement stmt= con.createStatement();

ResultSet rs= stmt.executeQuery(SQL);

while(rs.next())

String DNo= rs.getString("dept_no");

String DName= rs.getString("deptname");

dModel.addElement(DNo + "-" + DName);

jList1.setModel(dModel);
con.close();

catch (Exception e){

JOptionPane.showMessageDialog(this,e.getMessage());

e.printStackTrace();

private void jList1MouseClicked(java.awt.event.MouseEvent evt) {

// TODO add your handling code here:

try

Class.forName("com.mysql.jdbc.Driver");

Connection con= (Connection)


DriverManager.getConnection("jdbc:mysql://localhost:3306/school", "root", "aps");

String MDno= (String) jList1.getSelectedValue();

MDno= MDno.substring(0,3).trim();

String SQL= "Select * from Department where dept_no= '"+(MDno)+"'";

Statement stmt= con.createStatement();

ResultSet rs= stmt.executeQuery(SQL);

txtdno.enableInputMethods(false);

while (rs.next())

String DNo= rs.getString("dept_no");

String DName= rs.getString("deptname");


txtdno.setText(DNo);

txtdname.setText(DName);

catch (Exception e)

JOptionPane.showMessageDialog(this, e.getMessage());

e.printStackTrace();

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

// TODO add your handling code here:

txtdno.setText("");

txtdname.setText("");

}
//TUpdate.java

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

// TODO add your handling code here:

new StuMain().setVisible(true);

this.setVisible(false);

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

// TODO add your handling code here:

try

Class.forName("com.mysql.jdbc.Driver");

Connection con= (Connection)


DriverManager.getConnection("jdbc:mysql://localhost:3306/school", "root", "aps");

Statement stmt= con.createStatement();

String ntNo = txtNo.getText();

String name =txtName.getText();

double nSalary = Double.parseDouble(txtSal.getText());

String ndept = txtDept.getText();

String strSQL= "Update Teacher set Salary= "+(nSalary)+", tname='"+(name)+"',


dept_no= '"+(ndept)+"' where tno='"+(ntNo)+"'";

int rowsEffected=stmt.executeUpdate(strSQL);

if (rowsEffected== 0)

JOptionPane.showMessageDialog(this, "Record does not exist");


else

JOptionPane.showMessageDialog(this, "Record Updated");

catch (Exception e){

JOptionPane.showMessageDialog(this,e.getMessage());

e.printStackTrace();

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

// TODO add your handling code here:

txtNo.setText("");

txtName.setText("");

txtSal.setText("");

txtDept.setText("");

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

// TODO add your handling code here:

DefaultListModel dModel= (DefaultListModel)jList1.getModel();

txtNo.enableInputMethods(false);

try

Class.forName("com.mysql.jdbc.Driver");
Connection con= (Connection)
DriverManager.getConnection("jdbc:mysql://localhost:3306/school", "root", "aps");

String SQL= "SELECT * from Teacher";

Statement stmt= con.createStatement();

ResultSet rs= stmt.executeQuery(SQL);

while(rs.next())

String nTNo= rs.getString("tno");

String nTName= rs.getString("name");

dModel.addElement(nTNo + "-" + nTName);

jList1.setModel(dModel);

con.close();

catch (Exception e){

JOptionPane.showMessageDialog(this,e.getMessage());

e.printStackTrace();

private void jList1MouseClicked(java.awt.event.MouseEvent evt) {

// TODO add your handling code here:

try

Class.forName("com.mysql.jdbc.Driver");

Connection con= (Connection)


DriverManager.getConnection("jdbc:mysql://localhost:3306/school", "root", "aps");
String MTno= (String) jList1.getSelectedValue();

MTno= MTno.substring(0,3).trim();

String SQL= "Select * from Teacher where Tno= '"+(MTno)+"'";

Statement stmt= con.createStatement();

ResultSet rs= stmt.executeQuery(SQL);

txtNo.enableInputMethods(false);

while (rs.next())

String tcode= rs.getString("tno");

String name= rs.getString("tname");

String dept= rs.getString("deptNo");

Float sal= rs.getFloat("salary");

txtNo.setText(tcode);

txtName.setText(name);

txtSal.setText("" + sal);

txtDept.setText(dept);

catch (Exception e)

JOptionPane.showMessageDialog(this, e.getMessage());

e.printStackTrace();

}
//TDelete.java

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

// TODO add your handling code here:

try

Class.forName("com.mysql.jdbc.Driver");

Connection con= (Connection)


DriverManager.getConnection("jdbc:mysql://localhost:3306/school", "root", "aps");

Statement stmt= con.createStatement();

ResultSet rs= null;

String ntNo = txtNo.getText();

String strSQL= "Delete from Teacher where TNo= '"+(ntNo)+"'";

int rowsEffected=stmt.executeUpdate(strSQL);

if (rowsEffected== 0)

JOptionPane.showMessageDialog(this, "Record does not exist");

else

JOptionPane.showMessageDialog(this, "Record Deleted");

System.out.println(rowsEffected + "rows effected");

catch (Exception e){

JOptionPane.showMessageDialog(this,e.getMessage());

e.printStackTrace();
}

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

// TODO add your handling code here:

DefaultListModel dModel= (DefaultListModel)jList1.getModel();

txtNo.enableInputMethods(false);

try

Class.forName("com.mysql.jdbc.Driver");

Connection con= (Connection)


DriverManager.getConnection("jdbc:mysql://localhost:3306/school", "root", "aps");

String SQL= "SELECT * from Teacher";

Statement stmt= con.createStatement();

ResultSet rs= stmt.executeQuery(SQL);

while(rs.next())

String nTNo= rs.getString("tno");

String nTName= rs.getString("name");

dModel.addElement(nTNo + "-" + nTName);

jList1.setModel(dModel);

con.close();

catch (Exception e){


JOptionPane.showMessageDialog(this,e.getMessage());

e.printStackTrace();

private void jList1MouseClicked(java.awt.event.MouseEvent evt) {

// TODO add your handling code here:

try

Class.forName("com.mysql.jdbc.Driver");

Connection con= (Connection)


DriverManager.getConnection("jdbc:mysql://localhost:3306/school", "root", "aps");

String MTno= (String) jList1.getSelectedValue();

MTno= MTno.substring(0,3).trim();

String SQL= "Select * from Teacher where Tno= '"+(MTno)+"'";

Statement stmt= con.createStatement();

ResultSet rs= stmt.executeQuery(SQL);

txtNo.enableInputMethods(false);

while (rs.next())

String tcode= rs.getString("tno");

String name= rs.getString("tname");

String dept= rs.getString("deptNo");

Float sal= rs.getFloat("salary");

txtNo.setText(tcode);
txtName.setText(name);

txtSal.setText("" + sal);

txtDept.setText(dept);

catch (Exception e)

JOptionPane.showMessageDialog(this, e.getMessage());

e.printStackTrace();

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

// TODO add your handling code here:

new StuMain().setVisible(true);

this.setVisible(false);

}
//DDelete.java

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

// TODO add your handling code here:

DefaultListModel dModel= (DefaultListModel)jList1.getModel();

txtdno.enableInputMethods(false);

try

Class.forName("com.mysql.jdbc.Driver");

Connection con= (Connection)


DriverManager.getConnection("jdbc:mysql://localhost:3306/school", "root", "aps");

String SQL= "SELECT * from Teacher";

Statement stmt= con.createStatement();

ResultSet rs= stmt.executeQuery(SQL);

while(rs.next())

String nDNo= rs.getString("dept_no");

String nDName= rs.getString("dept_name");

dModel.addElement(nDNo + "-" + nDName);

jList1.setModel(dModel);

con.close();

catch (Exception e){

JOptionPane.showMessageDialog(this,e.getMessage());
e.printStackTrace();

private void jList1MouseClicked(java.awt.event.MouseEvent evt) {

// TODO add your handling code here:

try

Class.forName("com.mysql.jdbc.Driver");

Connection con= (Connection)


DriverManager.getConnection("jdbc:mysql://localhost:3306/school", "root", "aps");

String MDno= (String) jList1.getSelectedValue();

MDno= MDno.substring(0,3).trim();

String SQL= "Select * from department where dept_no= '"+(MDno)+"'";

Statement stmt= con.createStatement();

ResultSet rs= stmt.executeQuery(SQL);

txtdno.enableInputMethods(false);

while (rs.next())

String nDNo= rs.getString("Dno");

String nDName= rs.getString("Dname");

txtdno.setText(nDNo);

txtdname.setText(nDName);

}
catch (Exception e)

JOptionPane.showMessageDialog(this, e.getMessage());

e.printStackTrace();

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

// TODO add your handling code here:

try

Class.forName("com.mysql.jdbc.Driver");

Connection con= (Connection)


DriverManager.getConnection("jdbc:mysql://localhost:3306/school", "root", "aps");

Statement stmt= con.createStatement();

String DNo = txtdno.getText();

String strSQL= "Delete from Department where dept_no= '"+(DNo)+"'";

int rowsEffected=stmt.executeUpdate(strSQL);

if (rowsEffected== 0)

JOptionPane.showMessageDialog(this, "Record does not exist");

else

JOptionPane.showMessageDialog(this, "Record Deleted");

System.out.println(rowsEffected + "rows effected");

catch (Exception e){


JOptionPane.showMessageDialog(this,e.getMessage());

e.printStackTrace();

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

// TODO add your handling code here:

new StuMain().setVisible(true);

this.setVisible(false);

}
//TReport.java

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

// TODO add your handling code here:

//Before writing the following line, you should import the line:

//import javax.swing.table.*; At the top of your application

DefaultTableModel model= (DefaultTableModel) jTable1.getModel();

//Clear the existing table

int rows= model.getRowCount();

if(rows> 0)

for (int i= 0; i< rows; i++)

model.removeRow(0);

//SQL Query

String query = "SELECT *from teacher";

try

//connect to MySQL database

Class.forName("com.mysql.jdbc.Driver").newInstance();

Connection con= (Connection)

DriverManager.getConnection("jdbc:mysql://localhost:3306/school", "root", "aps");

//Create SQL Statement and execute query.


Statement stmt=(Statement) con.createStatement();

ResultSet rs= stmt.executeQuery(query);

// Iterate through the result and display on screen

while(rs.next())

String ntNo= rs.getString("T_No");

String ntName= rs.getString("T_Name");

String nSalary= rs.getString("Salary");

String ndept= rs.getString("Dept_No");

System.out.println(ntNo+ "|" + ntName + "|" + nSalary +"|"+ ndept);

model.addRow(new Object[] {ntNo, ntName, nSalary, ndept});

catch (Exception e)

JOptionPane.showMessageDialog(this, e.getMessage());

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

// TODO add your handling code here:

new StuMain().setVisible(true);

this.setVisible(false);

}
//DReport.java

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

// TODO add your handling code here:

//Before writing the following line, you should import the line:

//import javax.swing.table.*; At the top of your application

DefaultTableModel model= (DefaultTableModel) jTable1.getModel();

//Clear the existing table

int rows= model.getRowCount();

if(rows> 0)

for (int i= 0; i< rows; i++)

model.removeRow(0);

//SQL Query

String query = "SELECT *from DEPARTMENT";

try

//connect to MySQL database

Class.forName("com.mysql.jdbc.Driver").newInstance();

Connection con= (Connection)

DriverManager.getConnection("jdbc:mysql://localhost:3306/school", "root", "aps");

//Create SQL Statement and execute query.


Statement stmt=(Statement) con.createStatement();

ResultSet rs= stmt.executeQuery(query);

// Iterate through the result and display on screen

while(rs.next())

String DNo= rs.getString("dept_no");

String DName= rs.getString("deptname");

System.out.println(DNo+ "|" + DName);

model.addRow(new Object[] {DNo, DName});

catch (Exception e)

JOptionPane.showMessageDialog(this, e.getMessage());

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

// TODO add your handling code here:

new StuMain().setVisible(true);

this.setVisible(false);

You might also like