Advertisement
Guest User

Untitled

a guest
Jun 26th, 2016
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.56 KB | None | 0 0
  1. import java.sql.*;
  2. import java.awt.*;
  3. import java.awt.event.*;
  4. import javax.swing.*;
  5.  
  6. class form extends Frame implements ActionListener
  7. {
  8. Label ltitle;
  9. Label lusrid,lusrpswd;
  10.  
  11. TextField txtUsrid,txtUsrpswd;
  12.  
  13. Button btnSubmit, btnAdd;
  14.  
  15. form()
  16. {
  17. setSize(300,200);
  18. setVisible(true);
  19. setTitle("login screen");
  20. setLocation(200,200);
  21. setLayout(null);
  22. setBackground(Color.BLACK);
  23. setForeground(Color.WHITE);
  24.  
  25. ltitle=new Label("autentication screen");
  26. lusrid=new Label("Usrid");
  27. lusrpswd=new Label("Usrnme");
  28.  
  29. txtUsrid=new TextField();
  30. txtUsrpswd=new TextField();
  31.  
  32. btnSubmit=new Button("ok");
  33. btnAdd=new Button("insert");
  34.  
  35. ltitle.setBounds(90,60,150,20);
  36. lusrid.setBounds(70,90,80,20);
  37. txtUsrid.setBounds(160,90,100,20);
  38. txtUsrid.setForeground(Color.BLACK);
  39.  
  40. lusrpswd.setBounds(70,130,80,20);
  41. txtUsrpswd.setBounds(160,130,100,20);
  42. txtUsrpswd.setForeground(Color.BLACK);
  43. //txtUsrpswd.setEchoChar('?');
  44.  
  45. btnSubmit.setBounds(120,160,100,20);
  46. btnSubmit.setForeground(Color.RED);
  47. btnSubmit.addActionListener(this);
  48.  
  49. btnAdd.setBounds(160,200,100,20);
  50. btnAdd.setForeground(Color.RED);
  51. btnAdd.addActionListener(this);
  52.  
  53.  
  54. add(ltitle);
  55. add(lusrid);
  56. add(lusrpswd);
  57. add(txtUsrid);
  58. add(txtUsrpswd);
  59. add(btnSubmit);
  60. add(btnAdd);
  61. }
  62.  
  63. Connection conn=null;
  64. PreparedStatement st=null;
  65.  
  66. public void actionPerformed(ActionEvent e1)
  67. {
  68. try
  69. {
  70. Class.forName("oracle.jdbc.driver.OracleDriver");
  71. conn=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:Xe","SYSTEM","SYSTEM");
  72.  
  73. /*catch(SQLException e)
  74. {
  75. }*/
  76.  
  77. if(e1.getSource()==btnSubmit)
  78. {
  79. try
  80. {
  81. String SQL="select * from login where usrid=? and usrnme=?";
  82. st=conn.prepareStatement(SQL);
  83.  
  84. st.setString(1,txtUsrid.getText());
  85. st.setString(2,txtUsrpswd.getText());
  86.  
  87. ResultSet rs=st.executeQuery();
  88.  
  89. if(rs.next())
  90. {
  91. JOptionPane.showMessageDialog (null,"welcm usr");
  92. }
  93. else
  94. {
  95. JOptionPane.showMessageDialog (null,"chk");
  96. }
  97. }
  98. catch(SQLException e)
  99. {
  100. System.out.println(e.toString());
  101. }
  102. }
  103.  
  104. if(e1.getSource()==btnAdd)
  105. {
  106. try
  107. {
  108. String SQL="insert into login values(?,?)";
  109. st=conn.prepareStatement(SQL);
  110. st.setString(1,txtUsrid.getText());
  111. st.setString(2,txtUsrpswd.getText());
  112.  
  113. int n=st.executeUpdate();
  114. JOptionPane.showMessageDialog (null,"record inserted"+n);
  115. }
  116. catch(SQLException e)
  117. {
  118. System.out.println(e.toString());
  119. }
  120. }
  121.  
  122. }
  123. catch(ClassNotFoundException e)
  124. {
  125. System.out.println(e.toString());
  126. }
  127. catch(SQLException e)
  128. {
  129. System.out.println(e.toString());
  130. }
  131. finally
  132. {
  133. conn.close();
  134. }
  135. /*catch(ClassNotFoundException e)
  136. {
  137. System.out.println(e.toString());
  138. }*/
  139. /*catch(SQLException e)
  140. {
  141. System.out.println(e.toString());
  142. }
  143. }*/
  144.  
  145. public static void main(String args[])throws SQLException
  146. {
  147. new form();
  148. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement