Guest User

Untitled

a guest
Nov 29th, 2018
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.97 KB | None | 0 0
  1. package Model;
  2.  
  3. import java.beans.Statement;
  4. import java.sql.Connection;
  5. import java.sql.DriverManager;
  6. import java.sql.ResultSet;
  7. import java.sql.SQLException;
  8.  
  9.  
  10. public class Conexao {
  11. public Connection con;
  12. public Statement stmt;
  13. public ResultSet rs;
  14.  
  15. //Connect Mysql Endereço
  16. String url ="jdbc:mysql://localhost/";
  17. String driver = "";
  18. String user = "";
  19. String password = "";
  20.  
  21. //Metodos
  22. public void Connectar(){
  23. try{
  24. Class.forName(driver);
  25. con = DriverManager.getConnection(url,user,password);
  26.  
  27. stmt = (Statement) con.createStatement();
  28.  
  29. }catch(Exception e){
  30.  
  31.  
  32. }
  33.  
  34. }
  35.  
  36. //TESTANDO OUTRO TIPO DE CHAMADA BANCO DE DADOS
  37.  
  38. /*public static Connection creatConnection() throws SQLException{
  39. String url ="jdbc:mysql://localhost/id6275581_unit";
  40. String user = "id6275581_unitusername";
  41. String password = "123456";
  42. Connection conexaos = null;
  43. conexaos = DriverManager.getConnection(url,user,password);
  44.  
  45. return conexaos;
  46. }*/
  47.  
  48.  
  49.  
  50. }
  51.  
  52. package View;
  53.  
  54. import Model.Conexao;
  55. import java.beans.Statement;
  56. import java.sql.PreparedStatement;
  57. import java.sql.ResultSet;
  58. import java.sql.SQLException;
  59. import javax.swing.JOptionPane;
  60.  
  61.  
  62.  
  63. public class Login extends javax.swing.JFrame {
  64.  
  65.  
  66. public Login() {
  67. initComponents();
  68. }
  69.  
  70.  
  71. public void acessar(){
  72. try{
  73. Conexao connect = new Conexao();
  74. connect.Connectar();
  75. connect.stmt = (Statement) connect.con.createStatement();
  76.  
  77. String sql = "SELECT * FROM login";
  78.  
  79. //ResultSet rsTeste = connect.stmt.executeQuery(sql);
  80. // PreparedStatement ps = connect.con.prepareStatement(sql);
  81.  
  82. connect.rs = connect.stmt.executeQuery(sql);
  83. //ResultSet rss = ps.executeQuery();
  84.  
  85. //ps.execute();
  86.  
  87. connect.rs.first();
  88. if((txtUsuario.getText().equals(connect.rs.getString("username"))) && (txtSenha.getText().equals(connect.rs.getString("password")))){
  89.  
  90. }else{
  91. //AJAX FUTURO
  92. JOptionPane.showMessageDialog(null,"Senha ou Login Incorreto");
  93. }
  94.  
  95.  
  96.  
  97. }catch(SQLException e){
  98.  
  99. }
  100.  
  101. }
  102.  
  103. @SuppressWarnings("unchecked")
  104. // <editor-fold defaultstate="collapsed" desc="Generated Code">
  105. private void initComponents() {
  106.  
  107. label1 = new java.awt.Label();
  108. label2 = new java.awt.Label();
  109. label3 = new java.awt.Label();
  110. jButton1 = new javax.swing.JButton();
  111. jButton2 = new javax.swing.JButton();
  112. jScrollPane2 = new javax.swing.JScrollPane();
  113. txtUsuario = new javax.swing.JEditorPane();
  114. txtSenha = new javax.swing.JPasswordField();
  115.  
  116. setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  117. setTitle("Sisterma Login");
  118. setBackground(new java.awt.Color(0, 153, 102));
  119. setResizable(false);
  120.  
  121. label1.setFont(new java.awt.Font("Arial", 0, 20)); // NOI18N
  122. label1.setText("Sistema Academico - Login");
  123.  
  124. label2.setText("Usúario:");
  125.  
  126. label3.setText("Senha:");
  127.  
  128. jButton1.setText("Logar");
  129. jButton1.addActionListener(new java.awt.event.ActionListener() {
  130. public void actionPerformed(java.awt.event.ActionEvent evt) {
  131. jButton1ActionPerformed(evt);
  132. }
  133. });
  134.  
  135. jButton2.setText("Cadastre");
  136. jButton2.addActionListener(new java.awt.event.ActionListener() {
  137. public void actionPerformed(java.awt.event.ActionEvent evt) {
  138. jButton2ActionPerformed(evt);
  139. }
  140. });
  141.  
  142. txtUsuario.setName("txtUsuario"); // NOI18N
  143. jScrollPane2.setViewportView(txtUsuario);
  144.  
  145. txtSenha.setName("txtSenha"); // NOI18N
  146.  
  147. javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  148. getContentPane().setLayout(layout);
  149. layout.setHorizontalGroup(
  150. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  151. .addGroup(layout.createSequentialGroup()
  152. .addContainerGap()
  153. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  154. .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
  155. .addGap(0, 0, Short.MAX_VALUE)
  156. .addComponent(jButton2)
  157. .addGap(18, 18, 18)
  158. .addComponent(jButton1)
  159. .addGap(31, 31, 31))
  160. .addGroup(layout.createSequentialGroup()
  161. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  162. .addComponent(label2, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE)
  163. .addComponent(label3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  164. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  165. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
  166. .addComponent(txtSenha)
  167. .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 141, Short.MAX_VALUE))
  168. .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
  169. .addGroup(layout.createSequentialGroup()
  170. .addGap(63, 63, 63)
  171. .addComponent(label1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  172. .addGap(0, 93, Short.MAX_VALUE))
  173. );
  174. layout.setVerticalGroup(
  175. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  176. .addGroup(layout.createSequentialGroup()
  177. .addContainerGap()
  178. .addComponent(label1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  179. .addGap(38, 38, 38)
  180. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
  181. .addGroup(layout.createSequentialGroup()
  182. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
  183. .addComponent(label2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  184. .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  185. .addGap(20, 20, 20)
  186. .addComponent(label3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  187. .addComponent(txtSenha, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  188. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 128, Short.MAX_VALUE)
  189. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  190. .addComponent(jButton1)
  191. .addComponent(jButton2))
  192. .addContainerGap())
  193. );
  194.  
  195. pack();
  196. setLocationRelativeTo(null);
  197. }// </editor-fold>
  198.  
  199. private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
  200. this.acessar();
  201.  
  202. }
  203.  
  204. private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
  205. Cadastro cadastro = new Cadastro();
  206. cadastro.setVisible(true);
  207. }
  208.  
  209. /**
  210. * @param args the command line arguments
  211. */
  212. public static void main(String args[]) {
  213. /* Set the Nimbus look and feel */
  214. //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  215. /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
  216. * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  217. */
  218. try {
  219. for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  220. if ("Nimbus".equals(info.getName())) {
  221. javax.swing.UIManager.setLookAndFeel(info.getClassName());
  222. break;
  223. }
  224. }
  225. } catch (ClassNotFoundException ex) {
  226. java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  227. } catch (InstantiationException ex) {
  228. java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  229. } catch (IllegalAccessException ex) {
  230. java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  231. } catch (javax.swing.UnsupportedLookAndFeelException ex) {
  232. java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  233. }
  234. //</editor-fold>
  235.  
  236. /* Create and display the form */
  237. java.awt.EventQueue.invokeLater(new Runnable() {
  238. public void run() {
  239. new Login().setVisible(true);
  240. }
  241. });
  242. }
  243.  
  244. // Variables declaration - do not modify
  245. private javax.swing.JButton jButton1;
  246. private javax.swing.JButton jButton2;
  247. private javax.swing.JScrollPane jScrollPane2;
  248. private java.awt.Label label1;
  249. private java.awt.Label label2;
  250. private java.awt.Label label3;
  251. private javax.swing.JPasswordField txtSenha;
  252. private javax.swing.JEditorPane txtUsuario;
  253. // End of variables declaration
  254. }
Add Comment
Please, Sign In to add comment