Sie sind auf Seite 1von 4

PROGRAMS BASED ON CONNECTIVITY

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

String user,pass;

user=jTextField1.getText();

pass=new String(jPasswordField1.getPassword());

if (user.equals("maxfort") && pass.equals("rohini"))

new menu().setVisible(true);

else

JOptionPane.showMessageDialog(null," Wrong Password try again");

}
1. …….TO INSERT NEW DATA INTO MYSQL…….
private void jButton1ActionPerformed(java.awt.event.ActionEventevt) {
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection con = (Connection)
DriverManager.getConnection("jdbc:mysql://localhost:3306/xii","root","max@123");
Statement stmt=null;
ResultSetrs=null;
stmt=con.createStatement();
jTextField1.setText("");
jTextField2.setText("");
jTextArea1.setText("");
}
catch(Exception e)
{
JOptionPane.showMessageDialog(this,e.getMessage());
}
2. …….TO SAVE DATA INTO MYSQL…….
private void jButton2ActionPerformed(java.awt.event.ActionEventevt) {
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection con = (Connection)
DriverManager.getConnection("jdbc:mysql://localhost:3306/xii","root","max@123");
Statement stmt=null;
ResultSetrs=null;
stmt=con.createStatement();
int a = Integer.parseInt(jTextField1.getText());
String b = jTextField2.getText();
String c=jTextArea1.getText();
stmt.executeUpdate("insert into customer values("+(a)+",'"+(b)+"','"+(c)+"')");
}
catch(Exception e)
{
JOptionPane.showMessageDialog(this,e.getMessage());
}

3. …….TO DELETE DATA FROM MYSQL…….


private void jButton3ActionPerformed(java.awt.event.ActionEventevt) {
int x=0;
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection con = (Connection)
DriverManager.getConnection("jdbc:mysql://localhost:3306/xii","root","max@123");
Statement stmt=null;
ResultSetrs=null;
stmt=con.createStatement();
int a = Integer.parseInt(jTextField1.getText());
x=stmt.executeUpdate("delete from customer where cid="+(a)+"");
if(x==0)
JOptionPane.showMessageDialog(this,"not exist");
else
JOptionPane.showMessageDialog(this,"DELETED");
}
catch(Exception e)
{
JOptionPane.showMessageDialog(this,e.getMessage());
}

4. …….TO EXIT FROM NETBEANS…….


System.exit(0);

Das könnte Ihnen auch gefallen