Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import static cern.jet.math.Bessel.i1;
- import java.awt.*;
- import java.awt.event.*;
- import javax.swing.*;
- import java.io.*;
- import facedetection.*;
- import com.googlecode.javacv.*;
- import com.googlecode.javacv.cpp.*;
- import com.googlecode.javacpp.Loader;
- import com.mysql.jdbc.Connection;
- import java.sql.Blob;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- public class FaceRecognizer extends JFrame
- {
- // GUI components
- private FaceRecogPanel facePanel;
- private JButton recogBut;
- private JTextField nameField; // where the name (and distance info) appears
- private JButton done;
- private JButton exit;
- public FaceRecognizer()
- {
- super("Face Recognizer");
- FaceRecognizer fac;
- Container c = getContentPane();
- c.setLayout( new BorderLayout() );
- // Preload the opencv_objdetect module to work around a known bug.
- Loader.load(opencv_objdetect.class);
- facePanel = new FaceRecogPanel(this); // the sequence of pictures appear here
- c.add( facePanel, BorderLayout.CENTER);
- // button for recognizing a highlighted face
- done = new JButton("Done");
- recogBut = new JButton("Recognize Face");
- recogBut.addActionListener( new ActionListener() {
- public void actionPerformed(ActionEvent e)
- { nameField.setText("");
- recogBut.setEnabled(false);
- facePanel.setRecog();
- }
- });
- done.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e)
- {
- WelcomeStaffs wc = new WelcomeStaffs();
- Connection con = null;
- try{
- String url = "jdbc:mysql://localhost:3306/facedetection";
- Class.forName("com.mysql.jdbc.Driver");
- System.out.println("Conncection Success");
- con = (Connection) DriverManager.getConnection(url, "root", "2204");
- System.out.println("Database Connected");
- }
- catch(Exception ex)
- {
- System.out.println("Exception = "+ex);
- }
- String nm = nameField.getText().toUpperCase();
- String name ="",course="";
- System.out.println("Hello im till here!!");
- String subject = wc.subject_txt.getText();
- String staff = wc.staff_txt.getText();
- String day = wc.day_txt.getText();
- String date = wc.date_txt.getText();
- String time = wc.time_txt.getText();
- int roll_no = 0;
- System.out.println(subject+staff);
- String sql = "SELECT roll_no,name,course,photo FROM students WHERE name=?";
- try {
- PreparedStatement ps = con.prepareStatement(sql);
- ps.setString(1,nm);
- ResultSet rs = ps.executeQuery();
- while(rs.next()) //retrieving values from database and storing it!
- {
- roll_no = rs.getInt("roll_no");
- name = rs.getString("name");
- course = rs.getString("course");
- byte[]imagedata = rs.getBytes("photo");
- image = Toolkit.getDefaultToolkit().createImage(imagedata);
- format = new ImageIcon(image);
- System.out.println("Retrieved Data!!!!!!!");
- }
- } catch (SQLException ex) {
- Logger.getLogger(FaceRecognizer.class.getName()).log(Level.SEVERE, null, ex);
- }
- try{
- if(roll_no == 0 || name.equals("") || course.equals(""))
- {
- System.out.println("EMPTY");
- }
- else
- {
- sql = "INSERT INTO attendance(roll_no, name, course, subject, staff, day, time, date, photo) VALUES(?,?,?,?,?,?,?,?,?)";
- PreparedStatement ps1 = con.prepareStatement(sql);
- ps1.setInt(1,roll_no);
- ps1.setString(2,name);
- ps1.setString(3,course);
- ps1.setString(4,subject);
- ps1.setString(5,staff);
- ps1.setString(6,day);
- ps1.setString(7,time);
- ps1.setString(8,date);
- ps1.setBlob(9, (Blob) format);
- int i1 = ps1.executeUpdate();
- JOptionPane.showMessageDialog(null,i1+" Data Inserted");
- }
- }
- catch(Exception ec)
- {
- System.out.println(""+ec);
- }
- }
- });
- nameField = new JTextField(20); // for the name of the recognized face
- nameField.setEditable(false);
- JPanel p = new JPanel();
- p.add(recogBut);
- p.add( new JLabel("Name: "));
- p.add( nameField);
- p.add(done);
- c.add(p, BorderLayout.SOUTH);
- addWindowListener( new WindowAdapter() {
- public void windowClosing(WindowEvent e)
- { facePanel.closeDown(); // stop snapping pics
- /*Attendance_Chart ac = new Attendance_Chart();
- ac.setVisible(true);*/
- System.exit(0);
- }
- });
- pack();
- setResizable(false);
- setVisible(true);
- } // end of FaceRecognizer()
- public void setRecogName(final String faceName, final String dist)
- // update face name and its distance in the nameField; called from panel
- {
- SwingUtilities.invokeLater(new Runnable() {
- public void run()
- { nameField.setText( faceName);
- recogBut.setEnabled(true);
- }
- });
- } // end of setRecogName()
- // -------------------------------------------------------
- public static void main( String args[] )
- {
- new FaceRecognizer();
- }
- public ImageIcon format = null;
- public Image image = null;
- public Blob blob = null;
- }
- // end of FaceRecognizer class
- Conncection Success for Staffs
- detection/recognition duration: 9ms
- Database Connected for Staffs
- Table Created
- Conncection Success
- Database Connected
- Hello im till here!!
- Retrieved Data!!!!!!!
- java.lang.ClassCastException: javax.swing.ImageIcon cannot be cast to `java.sql.Blob`
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement