0% found this document useful (0 votes)
4 views

Complete Java Code

Uploaded by

nuuxmaxamed98
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)
4 views

Complete Java Code

Uploaded by

nuuxmaxamed98
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/ 7

SAVE Data Code

try
{
Class.forName("com.mysql.jdbc.Driver");
Connection con = (Connection)
DriverManager.getConnection("jdbc:mysql://localhost/bit","root","");
Statement std = (Statement) con.createStatement();
String qry = "INSERT INTO it6 VALUES ('" + txtid.getText() + "', '" +
txtname.getText() + "', '" + txtaddress.getText() + "')";
int x = std.executeUpdate(qry);
if (x==1)
{
JOptionPane.showMessageDialog(null, "insert suceesfully");
FillData();
}
else
{
JOptionPane.showMessageDialog(null, "inset Failled");
}
}
catch (Exception e)
{
JOptionPane.showMessageDialog(this, e);
}
}

Fill jtable Data

public void FillData()


{
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection con = (Connection)
DriverManager.getConnection("jdbc:mysql://localhost/bit","root","");
Statement std = (Statement) con.createStatement();
String qry ="select * from it6 ";
Statement pst = (Statement) con.prepareStatement(qry);
ResultSet rs;
rs=pst.executeQuery(qry);
jTable1.setModel(DbUtils.resultSetToTableModel(rs));
}
catch (Exception e)
{
JOptionPane.showMessageDialog(this, e);
}

}
When Clicked Fill Jtable
try
{
int row = jTable1.getSelectedRow();
String Table_Click=(jTable1.getModel().getValueAt(row, 0).toString());
Class.forName("com.mysql.jdbc.Driver");
Connection con = (Connection)
DriverManager.getConnection("jdbc:mysql://localhost/bit","root","");
Statement std = (Statement) con.createStatement();
String qry ="select * from it6 where ID='" + Table_Click+"'";
Statement pst = (Statement) con.prepareStatement(qry);
ResultSet rs;
rs=pst.executeQuery(qry);
if (rs.next())
{
String add1 = rs.getString("ID");
txtid.setText(add1);

String add2 = rs.getString("Name");


txtname.setText(add2);

String add4 = rs.getString("Address");


txtaddress.setText(add4);
}
else
{
JOptionPane.showMessageDialog(this, "not found data");

}
}
catch (Exception e)
{
JOptionPane.showMessageDialog(this, e);
}

}
Update Code:
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection con = (Connection)
DriverManager.getConnection("jdbc:mysql://localhost/bit","root","");
Statement std = (Statement) con.createStatement();
String qry = "UPDATE it6 SET Name = '" + txtname.getText() + "',
Address = '" + txtaddress.getText() + "' WHERE ID = '" + txtid.getText() +
"'";

int x = std.executeUpdate(qry);
if (x==1)
{
JOptionPane.showMessageDialog(null, "updated suceesfully");
FillData();
}
else
{
JOptionPane.showMessageDialog(null, "update Failled");
}
}
catch (Exception e)
{
JOptionPane.showMessageDialog(this, e);
}

}
Delete Code
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection con = (Connection)
DriverManager.getConnection("jdbc:mysql://localhost/bit","root","");
Statement std = (Statement) con.createStatement();
String qry ="delete from it6 where ID='" + txtid.getText()+"'";
int x = std.executeUpdate(qry);
if (x==1)
{
JOptionPane.showMessageDialog(null, "Deleted suceesfully");
FillData();
}
else
{
JOptionPane.showMessageDialog(null, "Deleted Failled");
}
}
catch (Exception e)
{
JOptionPane.showMessageDialog(this, e);
}

}
Search Code:
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection con = (Connection)
DriverManager.getConnection("jdbc:mysql://localhost/bit","root","");
String qry ="select * from it6 where ID='" + txtsearch.getText() +
"'" ;
Statement pst = (Statement) con.prepareStatement(qry);
ResultSet rs = pst.executeQuery(qry);

jTable1.setModel(net.proteanit.sql.DbUtils.resultSetToTableModel(rs));
}
catch (Exception e)
{
JOptionPane.showMessageDialog(this, e);
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy