Database Connectivity
Autor: sumitk02 • August 27, 2015 • Book/Movie Report • 643 Words (3 Pages) • 835 Views
String name=jTextField1.getText();
String email=jTextField2.getText();
String mobile=jTextField3.getText();
if(name.isEmpty()) {
JOptionPane.showMessageDialog(this, "Name not Entered");
}
else if(email.isEmpty()) {
JOptionPane.showMessageDialog(this, "Email not Entered");
}
else if(mobile.isEmpty()) {
JOptionPane.showMessageDialog(this, "Mobile not Entered");
}
else{
try{
Class.forName("java.sql.DriverManager");
Connection con=(Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/pk", "root", "1234");
Statement stmt=con.createStatement();
String query="insert into contactdiary values('"+name+"','"+email+"','"+mobile+"');";
stmt.executeUpdate(query);
JOptionPane.showMessageDialog(this, "Account added successfully.");
}
catch(Exception e){
JOptionPane.showMessageDialog(this, e.getMessage());
}
}
Add account
String name=jTextField1.getText();
int accno=Integer.parseInt(jTextField2.getText());
int deposit=Integer.parseInt(jTextField3.getText());
String address=jTextField4.getText();
String date=jTextField4.getText();
if(name.isEmpty()) {
JOptionPane.showMessageDialog(this, "Name not Entered");
}
else if(accno==0) {
JOptionPane.showMessageDialog(this, "Email not Entered");
}
else if(deposit==0) {
JOptionPane.showMessageDialog(this, "Deposit not Entered");
...