Sunteți pe pagina 1din 12

import com.mysql.jdbc.

Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.swing.JOptionPane;
import
javax.swing.table.DefaultTableModel;

Creating Database
mysqlpass = JOptionPane.showInputDialog("Enter mysql password");
try
{
//Loading Driver
Class.forName("com.mysql.jdbc.Connection");
//Connecting to the Database
Connection
con=(Connection)DriverManager.getConnection("jdbc:mysql://localhost/","ro
ot", mysqlpass);
Statement stmt = null;
stmt = con.createStatement();
String query = "CREATE DATABASE IF NOT EXISTS
digidiary";//Creating Database
stmt.execute(query);
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null,"error:"+e);//It Show "What is
the error?"
}

Event on jButton1;
one.setVisible(true);
try
{
// Loading Driver
Class.forName("com.mysql.jdbc.Connection");
//Connecting to the Database
Connection
con=(Connection)DriverManager.getConnection("jdbc:mysql://localhost/digidi
ary","root", mysqlpass);
Statement stmt = null;
stmt = con.createStatement();
String query = "CREATE TABLE IF NOT EXISTS signin(uname
varchar(15),pass varchar(15));";
stmt.execute(query);
stmt.close();
con.close();
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null,"error:"+e);//It Show "What is
the error?"
}

Event on jToggleButton1;
String pws,uid;
int tester=0;

uid= jTextField1.getText();
if(jTextField1.getText().length()==0)
{
JOptionPane.showMessageDialog(null,"User ID Should Not Be Empty
");
jTextField1.requestFocus();
}
else
{
pws=new String (jPasswordField1.getPassword());
int len=pws.length();
if(len>0)
{
try
{
//Loading Driver
Class.forName("com.mysql.jdbc.Connection");
//Connecting to the Database
Connection
con=(Connection)DriverManager.getConnection("jdbc:mysql://localhost/digidi
ary","root", mysqlpass);
Statement stmt = null;
stmt = con.createStatement();
ResultSet rs=null;
String query1="SELECT * FROM signin WHERE uname='"+uid+"'
AND pass='"+pws+"';";
rs=stmt.executeQuery(query1);
while(rs.next())
{
tester=1;
}

if(tester==1)
two.setVisible(true);
else
System.exit(0);
stmt.close();
con.close();
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null,"error:"+e);
}
}
else
JOptionPane.showMessageDialog(null,"Please Enter Password");//It
Show "What is the error?"
}

Event on jMenuItem1;
three.setVisible(true);

Event on threeWindow1;
jTextField5.setEditable(false);
try
{
//Loading Driver
Class.forName("com.mysql.jdbc.Connection");
//Connecting to the Database
Connection
con=(Connection)DriverManager.getConnection("jdbc:mysql://localhost/digidi
ary","root", mysqlpass);

Statement stmt = null;


stmt = con.createStatement();
String query = "CREATE TABLE IF NOT EXISTS enteries(name
varchar(35) not null,phoneno integer(15) Primary Key, age integer(4),sex
varchar(3) check((sex='M') or (sex='F')),emailid varchar(39),address
varchar(65));";
stmt.execute(query);
stmt.close();
con.close();
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null,"error:"+e);//It Show "What is
the error?"
}

Event on jToggleButton2;
String name,emailid,sex,address;

//Initializing Variable

int phoneno,age;
name=jTextField2.getText();

//Taking Values

sex=jTextField5.getText();
emailid=jTextField6.getText();
address=jTextArea1.getText();
phoneno=Integer.parseInt(jTextField3.getText());
age =Integer.parseInt(jTextField4.getText());
try
{
//Loading Driver

Class.forName("com.mysql.jdbc.Connection");
//Connecting to the Database
Connection
con=(Connection)DriverManager.getConnection("jdbc:mysql://localhost/digidi
ary","root", mysqlpass);
Statement stmt = null;
stmt = con.createStatement();
String query = "INSERT INTO enteries
VALUES('"+name+"','"+phoneno+"','"+age+"','"+sex+"','"+emailid+"','"+addres
s+"');";
stmt.executeUpdate(query);
JOptionPane.showMessageDialog(null,"Record Has Been Inserted");
stmt.close();
con.close();
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null,"error:"+e);//It Show "What is
the error?"
}

Event on jToggleButton3;
jTextField2.setText(null);
jTextField3.setText(null);
jTextField4.setText(null);
jTextField5.setText(null);
jTextField6.setText(null);
jTextArea1.setText(null);
jRadioButton1.setSelected(false);
jRadioButton2.setSelected(false);

Event on jMenuItem2;
four.setVisible(true);

Event on jButton2;
String name;
int phoneno;
name=jTextField7.getText();
phoneno=Integer.parseInt(jTextField8.getText());
try
{
//Loading Driver
Class.forName("com.mysql.jdbc.Connection");
//Connecting to the Database
Connection
con=(Connection)DriverManager.getConnection("jdbc:mysql://localhost/digidi
ary","root", mysqlpass);
Statement stmt = null;
stmt = con.createStatement();
String query = "INSERT INTO mobile
VALUES('"+name+"','"+phoneno+"');";
stmt.executeUpdate(query);
JOptionPane.showMessageDialog(null,"Record Has Been Inserted");
stmt.close();
con.close();
}

catch(Exception e)
{
JOptionPane.showMessageDialog(null,"error:"+e);//It Show "What is
the error?"
}

Event on fourWindow;
try
{
//Loading Driver
Class.forName("com.mysql.jdbc.Connection");
//Connecting to the Database
Connection
con=(Connection)DriverManager.getConnection("jdbc:mysql://localhost/digidi
ary","root", mysqlpass);
Statement stmt = null;
stmt = con.createStatement();
String query = "CREATE TABLE IF NOT EXISTS mobile(name
varchar(35) not null,phoneno integer(15) Primary Key);";
stmt.execute(query);
stmt.close();
con.close();
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null,"error:"+e);//It Show "What is
the error?"

Event on jButton3;
jTextField7.setText(null);
jTextField8.setText(null);

Event on jMenuItem3;
five.setVisible(true);

Event on jButton4;
String name,emailid;
name=jTextField9.getText();
emailid=jTextField10.getText();
try
{
//Loading Driver
Class.forName("com.mysql.jdbc.Connection");
//Connecting to the Database
Connection
con=(Connection)DriverManager.getConnection("jdbc:mysql://localhost/digidi
ary","root", mysqlpass);
Statement stmt = null;
stmt = con.createStatement();
String query = "INSERT INTO eid VALUES('"+name+"','"+emailid+"');";
stmt.executeUpdate(query);

JOptionPane.showMessageDialog(null,"Record Has Been Inserted");


stmt.close();
con.close();
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null,"error:"+e);//It Show "What is
the error?"
}

Event on fiveWindow;
try
{
//Loading Driver
Class.forName("com.mysql.jdbc.Connection");
//Connecting to the Database
Connection
con=(Connection)DriverManager.getConnection("jdbc:mysql://localhost/digidi
ary","root", mysqlpass);
Statement stmt = null;
stmt = con.createStatement();
String query = "CREATE TABLE IF NOT EXISTS eid(name varchar(35)
not null,emailid varchar(65) Primary Key);";
stmt.execute(query);
stmt.close();
con.close();
}
catch(Exception e)
{

JOptionPane.showMessageDialog(null,"error:"+e);//It Show "What is


the error?"
}

S-ar putea să vă placă și