Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.*;
- import java.awt.*;
- import java.awt.event.*;
- import javax.swing.*;
- class form extends Frame implements ActionListener
- {
- Label ltitle;
- Label lusrid,lusrpswd;
- TextField txtUsrid,txtUsrpswd;
- Button btnSubmit, btnAdd;
- form()
- {
- setSize(300,200);
- setVisible(true);
- setTitle("login screen");
- setLocation(200,200);
- setLayout(null);
- setBackground(Color.BLACK);
- setForeground(Color.WHITE);
- ltitle=new Label("autentication screen");
- lusrid=new Label("Usrid");
- lusrpswd=new Label("Usrnme");
- txtUsrid=new TextField();
- txtUsrpswd=new TextField();
- btnSubmit=new Button("ok");
- btnAdd=new Button("insert");
- ltitle.setBounds(90,60,150,20);
- lusrid.setBounds(70,90,80,20);
- txtUsrid.setBounds(160,90,100,20);
- txtUsrid.setForeground(Color.BLACK);
- lusrpswd.setBounds(70,130,80,20);
- txtUsrpswd.setBounds(160,130,100,20);
- txtUsrpswd.setForeground(Color.BLACK);
- //txtUsrpswd.setEchoChar('?');
- btnSubmit.setBounds(120,160,100,20);
- btnSubmit.setForeground(Color.RED);
- btnSubmit.addActionListener(this);
- btnAdd.setBounds(160,200,100,20);
- btnAdd.setForeground(Color.RED);
- btnAdd.addActionListener(this);
- add(ltitle);
- add(lusrid);
- add(lusrpswd);
- add(txtUsrid);
- add(txtUsrpswd);
- add(btnSubmit);
- add(btnAdd);
- }
- Connection conn=null;
- PreparedStatement st=null;
- public void actionPerformed(ActionEvent e1)
- {
- try
- {
- Class.forName("oracle.jdbc.driver.OracleDriver");
- conn=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:Xe","SYSTEM","SYSTEM");
- /*catch(SQLException e)
- {
- }*/
- if(e1.getSource()==btnSubmit)
- {
- try
- {
- String SQL="select * from login where usrid=? and usrnme=?";
- st=conn.prepareStatement(SQL);
- st.setString(1,txtUsrid.getText());
- st.setString(2,txtUsrpswd.getText());
- ResultSet rs=st.executeQuery();
- if(rs.next())
- {
- JOptionPane.showMessageDialog (null,"welcm usr");
- }
- else
- {
- JOptionPane.showMessageDialog (null,"chk");
- }
- }
- catch(SQLException e)
- {
- System.out.println(e.toString());
- }
- }
- if(e1.getSource()==btnAdd)
- {
- try
- {
- String SQL="insert into login values(?,?)";
- st=conn.prepareStatement(SQL);
- st.setString(1,txtUsrid.getText());
- st.setString(2,txtUsrpswd.getText());
- int n=st.executeUpdate();
- JOptionPane.showMessageDialog (null,"record inserted"+n);
- }
- catch(SQLException e)
- {
- System.out.println(e.toString());
- }
- }
- }
- catch(ClassNotFoundException e)
- {
- System.out.println(e.toString());
- }
- catch(SQLException e)
- {
- System.out.println(e.toString());
- }
- finally
- {
- conn.close();
- }
- /*catch(ClassNotFoundException e)
- {
- System.out.println(e.toString());
- }*/
- /*catch(SQLException e)
- {
- System.out.println(e.toString());
- }
- }*/
- public static void main(String args[])throws SQLException
- {
- new form();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement