Guest User

Untitled

a guest
Jun 20th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.33 KB | None | 0 0
  1. Connection con = new ConnectionFactory().getConnection();
  2. int id = 0;
  3.  
  4. public int getId() {
  5. return id;
  6. }
  7.  
  8. public void setId(int id) {
  9. String query = "SELECT idCurso FROM Curso WHERE nomeCurso = "
  10. + "' xiu ' AND tipoCurso = "
  11. + "' Técnico '";
  12. try{
  13. PreparedStatement stmt = con.prepareStatement(query);
  14. ResultSet rs = stmt.executeQuery();
  15. while (rs.next()){
  16. id = rs.getInt("idCurso");
  17. }
  18. }catch (SQLException ex){
  19. ex.printStackTrace();
  20. }
  21. this.id = id;
  22. }
  23.  
  24. public Teste4() {
  25.  
  26.  
  27. initComponents();
  28.  
  29. }
  30.  
  31. /**
  32. * This method is called from within the constructor to initialize the form.
  33. * WARNING: Do NOT modify this code. The content of this method is always
  34. * regenerated by the Form Editor.
  35. */
  36. @SuppressWarnings("unchecked")
  37. // <editor-fold defaultstate="collapsed" desc="Generated Code">
  38. private void initComponents() {
  39.  
  40. jButton1 = new javax.swing.JButton();
  41.  
  42. setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  43.  
  44. jButton1.setText("jButton1");
  45. jButton1.addActionListener(new java.awt.event.ActionListener() {
  46. public void actionPerformed(java.awt.event.ActionEvent evt) {
  47. jButton1ActionPerformed(evt);
  48. }
  49. });
  50.  
  51. javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  52. getContentPane().setLayout(layout);
  53. layout.setHorizontalGroup(
  54. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  55. .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
  56. .addContainerGap(170, Short.MAX_VALUE)
  57. .addComponent(jButton1)
  58. .addGap(157, 157, 157))
  59. );
  60. layout.setVerticalGroup(
  61. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  62. .addGroup(layout.createSequentialGroup()
  63. .addGap(139, 139, 139)
  64. .addComponent(jButton1)
  65. .addContainerGap(138, Short.MAX_VALUE))
  66. );
  67.  
  68. pack();
  69. }// </editor-fold>
  70.  
  71. private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
  72. JFNovoCurso janela = new JFNovoCurso();
  73. System.out.println(getId());
  74. janela.setId(getId());
  75. janela.setVisible(true);
  76. }
  77.  
  78. /**
  79. * @param args the command line arguments
  80. */
  81. public static void main(String args[]) {
  82. /* Set the Nimbus look and feel */
  83. //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  84. /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
  85. * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  86. */
  87. try {
  88. for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  89. if ("Nimbus".equals(info.getName())) {
  90. javax.swing.UIManager.setLookAndFeel(info.getClassName());
  91. break;
  92. }
  93. }
  94. } catch (ClassNotFoundException ex) {
  95. java.util.logging.Logger.getLogger(Teste4.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  96. } catch (InstantiationException ex) {
  97. java.util.logging.Logger.getLogger(Teste4.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  98. } catch (IllegalAccessException ex) {
  99. java.util.logging.Logger.getLogger(Teste4.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  100. } catch (javax.swing.UnsupportedLookAndFeelException ex) {
  101. java.util.logging.Logger.getLogger(Teste4.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  102. }
  103. //</editor-fold>
  104.  
  105. /* Create and display the form */
  106. java.awt.EventQueue.invokeLater(new Runnable() {
  107. public void run() {
  108. new Teste4().setVisible(true);
  109. }
  110. });
  111. }
  112.  
  113. // Variables declaration - do not modify
  114. private javax.swing.JButton jButton1;
  115. // End of variables declaration
  116.  
  117. Connection con;
  118.  
  119. public Connection getConnection(){
  120.  
  121. String url = "jdbc:mysql://localhost:3306/tcc";
  122. try {
  123. return (Connection) DriverManager.getConnection(url,"root", "GUstavo08!");
  124. }catch(SQLException ex){
  125. System.out.println("Problemas na conexão " + ex.getMessage());
  126. return null;
  127. }
  128. }
Add Comment
Please, Sign In to add comment