Advertisement
buzzonit

CRUD

Jul 22nd, 2016
332
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.94 KB | None | 0 0
  1. http://www70.zippyshare.com/v/QXk4KBiU/file.html
  2.  
  3.  
  4. Botao adicionar
  5.  
  6. try{
  7.  
  8. Connection con;
  9. con = DriverManager.getConnection("jbdc:mysql://127.0.01/Nome_Banco","usuario","senha");
  10. String sql;//string para receber a script
  11. sql = "INSERT INTO cad_alunos(campo1,campo2,campo3)VALUES (?,?,?)";
  12. /*
  13. */
  14. PreparedStatement (sql);
  15. ps = con.prepareStatement(sql);
  16. ps.setString(1, jTextField2.getText());
  17. ps.setString(2, jTextField4.getText());
  18. ps.setString(3, jTextField6.getText());
  19.  
  20.  
  21. int res = ps.executeUpdate();
  22. if (res>0){
  23. JOptionPane.showMessageDialog(null, "Cadastro efetuado com sucesso");}
  24. else{
  25. JOptionPane.showMessageDialog(null, "falha no cadastro");}
  26. }
  27. catch (SQLException ex) //Se ocorrer algum erro uma mesangem e exibida.
  28. {
  29. JOptionPane.showMessageDialog(null, "SQLException: ");
  30. }
  31. }
  32.  
  33.  
  34. privad void
  35.  
  36. try{
  37. Class.forName("com.mysql.jbdc.Driver");
  38. Connection con;
  39. con = DriverManager.getConnection("jbdc:mysql://localhost:3306/projeto_crud_java","root","1234");
  40. String sql;
  41. sql = "UPDATE cad_alunos set Nome = ?,Endereco=?,Bairro=?,CEP=?,Cidade=?,Estado=?,Fone=?,CEL=?,estadocivil=?,"
  42. + "Email=?,Obs=?,login = ? where ID_alunos = ?";
  43. PreparedStatement ps;
  44. ps = con.prepareStatement (sql);
  45. ps.setString(1, jTextFDield1.getText());
  46. ps.setString(2, jTextFDield2.getText());
  47. ps.setString(3, jTextFDield3.getText());
  48. ps.setString(4, jTextFDield4.getText());
  49. ps.setString(5, jTextFDield5.getText());
  50. ps.setString(6, jComboBox.getSlectedItem().toString());
  51. ps.setString(7, jTextFDield7.getText());
  52. ps.setString(8, jTextFDield8.getText());
  53. ps.setString(9, jTextFDield9.getText());
  54. ps.setString(10, jComboBox2.getSelectedItem().toString());
  55. ps.setString(11, jTextFDield11.getText());
  56. ps.setString(12, jTextFDield12.getText());
  57. ps.setString(13, jTextFDield13.getText());
  58. ps.setString(1, jTextFDield1.getText());
  59. int res = ps.executeUpdate();
  60. if (res > 0) {
  61. JOptionPane.showMessageDialog(null, "Alterado com sucesso");}
  62. else {
  63. JOptionPane.showMessageDialog(null, "Nenhum registro alterado");}
  64. } catch (SQLException ex)
  65. }
  66. JOptionPane.showMessageDialog(null, "SQLException: " + ex.getMessage () + "\nSQLState: + ex.getSQLState() + "\nVendorError: + ex.getErrorCode());
  67. }catch (ClassNotFoundException ex) {
  68. logger.getLogger(JFRCurso.Class.GetName()).log(Level.SEVERE,null, ex);
  69. }
  70.  
  71.  
  72.  
  73. privad void
  74.  
  75. try{
  76. Class.forName("com.mysql.jbdc.Driver");
  77. Connection con;
  78. con = DriverManager.getConnection("jbdc:mysql://localhost:3306/projeto_crud_java","root","1234");
  79. String sql = "Select * from cad_alunos Where ID_alunos =? ";
  80.  
  81.  
  82. PrepareStatement ps = con.prepareStatement (sql);
  83. ps.setString(1,jTextFDield1.getText());
  84. Result rs;
  85. rs = ps.executeQuery();
  86. if (rs.next()) {
  87.  
  88.  
  89.  
  90.  
  91. jTextFDield1.getText(""Nome));
  92. jTextFDield2.getText("Endereco"));
  93. jTextFDield3.getText("Cidade"));
  94. jTextFDield4.getText("Bairro"));
  95. jTextFDield5.getText(""));
  96. jComboBox1.setSelectedItem(rs.getString("Estado"));
  97. jTextFDield7.getText("Cep"));
  98. jTextFDield8.getText("Fone"));
  99. jTextFDield9.getText("CEL"));
  100. jTextFDield11.getText("Email"));
  101. jTextFDield11.getText("Obs"));
  102. } else{
  103.  
  104.  
  105. JOptionPane.showMessageDialog(null, "Registro nao encontrado");}
  106. }
  107.  
  108. } catch (SQLException ex)
  109. {
  110. JOptionPane.showMessageDialog(null, "SQLException: " + ex.getMessage () + "\nSQLState: + ex.getSQLState()
  111. + "\nVendorError: + ex.getErrorCode());
  112. }catch (ClassNotFoundException ex) {
  113. Logger.getLogger(JFRCurso.Class.getName()).log(Level.SEVERE, null, ex);
  114. }
  115.  
  116.  
  117. http://www119.zippyshare.com/v/pcJvARiN/file.html
  118. https://www.youtube.com/watch?v=koDp-bTdVTk
  119. https://www.youtube.com/watch?v=8D-CEtWAgHk JAVA MOBILE
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement