Sie sind auf Seite 1von 27

package petshop;

import java.sql.*;
import javax.swing.JOptionPane;

public class login extends javax.swing.JFrame {

/**
* Creates new form login
*/
public login() {
initComponents();
}
private void
jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection
con=DriverManager.getConnection("jdbc:mysql://localhost/pets
hop","root","");
Statement st=con.createStatement();
String un,p,q;
un=t1.getText();
p=t2.getText();
q="select * from login where username='" + un +"' and
password='"+p+"'";
ResultSet rs=st.executeQuery(q);
if(rs.next())
{
JOptionPane.showMessageDialog(this,"Welcome");
Menu m =new Menu();
m.setVisible(true);
}
else
JOptionPane.showMessageDialog(this,"Invalid
username or password");

}
catch(Exception e)
{
}
}
package petshop;
public class Menu extends javax.swing.JFrame {

/**
* Creates new form Menu
*/
public Menu() {
initComponents();
}
private void
jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
addPet p=new addPet();
p.setVisible(true);
}

private void
jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
searchPet a=new searchPet();
a.setVisible(true);
}

private void
jMenuItem5ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
addCustomer c=new addCustomer();
c.setVisible(true);
}

private void
jMenuItem6ActionPerformed(java.awt.event.ActionEvent evt) {
searchPet p=new searchPet();
p.setVisible(true);
}

private void
jMenuItem4ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
showAllPets p=new showAllPets();
p.setVisible(true);
}

private void
jMenuItem8ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
showCust c =new showCust();
c.setVisible(true);
}

private void
jMenuItem10ActionPerformed(java.awt.event.ActionEvent evt)
{
// TODO add your handling code here:
SellPet p=new SellPet();
p.setVisible(true);
}

private void
DeleteActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
delPet d=new delPet();
d.setVisible(true);
}

private void
jMenuItem7ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
delcust d=new delcust();
d.setVisible(true);
}
package petshop;
import java.sql.*;
import javax.swing.JOptionPane;
public class addPet extends javax.swing.JFrame {

/**
* Creates new form addPet
*/
public addPet() {
initComponents();
}
private void
jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection
con=DriverManager.getConnection("jdbc:mysql://localhost/pets
hop","root","");
Statement st=con.createStatement();
String q,an,pid,brd,gn,age,clr,typ;
an=C1.getSelectedItem().toString();
pid=t1.getText();
brd=t2.getText();
if(r1.isSelected())
gn="Male";
else
gn="Female";
age=t4.getText();
clr=t3.getText();
if(r3.isSelected())
typ="Adoption";
else
typ="Sale";
q="insert into pets values('" + an
+"','"+pid+"','"+brd+"','"+gn+"','"+clr+"','"+age+"','"+typ+"')";
st.executeUpdate(q);
JOptionPane.showMessageDialog(this,"Saved");
}
catch(Exception e)
{
JOptionPane.showMessageDialog(this,e.toString());
}}
package petshop;

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

public class searchPet extends javax.swing.JFrame {

/**
* Creates new form searchPet
*/
public searchPet() {
initComponents();
}
private void
jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection
con=DriverManager.getConnection("jdbc:mysql://localhost/pets
hop","root","");
Statement st=con.createStatement();
String q,an,pid,brd,gn,age,clr,typ;
pid=t1.getText();
q="select * from pets where petid='"+pid+"'";
ResultSet rs=st.executeQuery(q);
if(rs.next())
{
an=rs.getString("animal");
brd=rs.getString("breed");
gn=rs.getString("gender");
clr=rs.getString("color");
age=rs.getString("age");
typ=rs.getString("type");
t2.setText(an);
t3.setText(brd);
t4.setText(gn);
t5.setText(age);
t6.setText(clr);
t7.setText(typ);
}
else
{
JOptionPane.showMessageDialog(this, "Not found");
t2.setText("");
t3.setText("");
t4.setText("");
t5.setText("");
t6.setText("");
t7.setText("");
}
}
catch(Exception e)
{

}
}
package petshop;
import java.sql.*;
import javax.swing.JOptionPane;

public class delPet extends javax.swing.JFrame {

/**
* Creates new form delPet
*/
public delPet() {
initComponents();
}
private void
jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection
con=DriverManager.getConnection("jdbc:mysql://localhost/pets
hop","root","");
Statement st=con.createStatement();
String q,an,pid,brd;
pid=t1.getText();
q="select * from pets where petid='"+pid+"'";
ResultSet rs=st.executeQuery(q);
if(rs.next())
{
an=rs.getString("animal");
brd=rs.getString("breed");
t2.setText(an);
t3.setText(brd);

}
else
{
JOptionPane.showMessageDialog(this, "Not found");
t2.setText("");
t3.setText("");

}
}
catch(Exception e)
{

}
}

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

try
{
Class.forName("com.mysql.jdbc.Driver");
Connection
con=DriverManager.getConnection("jdbc:mysql://localhost/pets
hop","root","");
Statement st=con.createStatement();
String q,pid;
pid=t1.getText();
q="delete from pets where petid='"+pid+"'";

st.executeUpdate(q);
JOptionPane.showMessageDialog(this, "Deleted");
t2.setText("");
t3.setText("");

}
catch(Exception e)
{

}
package petshop;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
public class showAllPets extends javax.swing.JFrame {

/**
* Creates new form showAllPets
*/
public showAllPets() {
initComponents();
}

private void
jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection
con=DriverManager.getConnection("jdbc:mysql://localhost/pets
hop","root","");
Statement st=con.createStatement();
String q,an,pid,brd,gn,age,clr,typ;
DefaultTableModel
df=(DefaultTableModel)jTable1.getModel();

q="select * from pets";


ResultSet rs=st.executeQuery(q);
while(rs.next())
{
pid=rs.getString("petid");
an=rs.getString("animal");
brd=rs.getString("breed");
gn=rs.getString("gender");
clr=rs.getString("color");
age=rs.getString("age");
typ=rs.getString("type");
String row[]={pid,an,brd,gn,age,clr,typ};
df.addRow(row);

}
}
catch(Exception e)
{

}
}
package petshop;

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

public class SellPet extends javax.swing.JFrame {


/**
* Creates new form SellPet
*/
public SellPet() {
initComponents();
}
private void
jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection
con=DriverManager.getConnection("jdbc:mysql://localhost/pets
hop","root","");
Statement st=con.createStatement();
String q,cn,ph,ad,em,pref;
cn=t1.getText();
q="select * from customer where cname='"+cn+"'";
ResultSet rs=st.executeQuery(q);
if(rs.next())
{
pref=rs.getString("pref");
String q1="select * from pets where
animal='"+pref+"'";
Statement s2=con.createStatement();
ResultSet rs2=s2.executeQuery(q1);
while(rs2.next())
{
cmb1.addItem(rs2.getString("petid"));
}

}
else
{
JOptionPane.showMessageDialog(this, "Not found");

}
}
catch(Exception e)
{

}
}

private void
cmb1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection
con=DriverManager.getConnection("jdbc:mysql://localhost/pets
hop","root","");
Statement st=con.createStatement();
String q,pid,br,g,typ,ag;
pid=cmb1.getSelectedItem().toString();
String q1="select * from pets where petid='"+pid+"'";
ResultSet rs=st.executeQuery(q1);
if(rs.next())
{
br=rs.getString("breed");
g=rs.getString("gender");
typ=rs.getString("type");
ag=rs.getString("age");
t2.setText(br +" ");
t3.setText(g +" ");
t4.setText(typ +" ");
t5.setText(ag +" ");
}
else
{
JOptionPane.showMessageDialog(this, "Not found");

}
}
catch(Exception e)
{

private void
jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection
con=DriverManager.getConnection("jdbc:mysql://localhost/pets
hop","root","");
Statement st=con.createStatement();
String q,pid;
pid=cmb1.getSelectedItem().toString();
q="delete from pets where petid='"+pid+"'";
st.executeUpdate(q);
JOptionPane.showMessageDialog(null, "Sold!!");
}
catch(Exception e)
{}}
package petshop;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import javax.swing.JOptionPane;
public class addCustomer extends javax.swing.JFrame {

/**
* Creates new form addCustomer
*/
public addCustomer() {
initComponents();
}
private void
jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection
con=DriverManager.getConnection("jdbc:mysql://localhost/pets
hop","root","");
Statement st=con.createStatement();
String q,cn,ph,adr,em,pref;
cn=t1.getText();
ph=t2.getText();
adr=t3.getText();
em=t4.getText();
pref=t5.getText();
q="insert into customer values('" + cn
+"','"+ph+"','"+adr+"','"+em+"','"+pref+"')";
st.executeUpdate(q);
JOptionPane.showMessageDialog(this,"Saved");
}
catch(Exception e)
{
JOptionPane.showMessageDialog(this,e.toString());
}

}
package petshop;
import java.sql.*;
import javax.swing.table.DefaultTableModel;
public class showCust extends javax.swing.JFrame {

/**
* Creates new form showCust
*/
public showCust() {
initComponents();
}

private void
jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection
con=DriverManager.getConnection("jdbc:mysql://localhost/pets
hop","root","");
Statement st=con.createStatement();
String q,cn,ph,ad,em,pref;
DefaultTableModel
df=(DefaultTableModel)jTable1.getModel();

q="select * from customer";


ResultSet rs=st.executeQuery(q);
while(rs.next())
{
ph=rs.getString("phone");
ad=rs.getString("address");
em=rs.getString("email");
pref=rs.getString("pref");
cn=rs.getString("cname");

String row[]={cn,ph,ad,em,pref};
df.addRow(row);

}
}
catch(Exception e)
{

}
}
package petshop;
import java.sql.*;
import javax.swing.JOptionPane;
public class searchcustomer extends javax.swing.JFrame {

/**
* Creates new form searchcustomer
*/
public searchcustomer() {
initComponents();
}
private void
jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection
con=DriverManager.getConnection("jdbc:mysql://localhost/pets
hop","root","");
Statement st=con.createStatement();
String q,cn,ph,ad,em,pref;
cn=t1.getText();
q="select * from customer where cname='"+cn+"'";
ResultSet rs=st.executeQuery(q);
if(rs.next())
{
ph=rs.getString("phone");
ad=rs.getString("address");
em=rs.getString("email");
pref=rs.getString("pref");

t2.setText(ph);
t3.setText(ad);
t4.setText(em);
t5.setText(pref);

}
else
{
JOptionPane.showMessageDialog(this, "Not found");
t2.setText("");
t3.setText("");
t4.setText("");
t5.setText("");

}
}
catch(Exception e)
{

}
}

Das könnte Ihnen auch gefallen