Advertisement
Guest User

bilabilu

a guest
Nov 15th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 27.41 KB | None | 0 0
  1. import java.sql.Connection;
  2. import java.sql.DriverManager;
  3. import java.sql.PreparedStatement;
  4. import java.sql.ResultSet;
  5. import java.sql.SQLException;
  6. import java.sql.Statement;
  7.  
  8. /**
  9. *
  10. * @author Lauro
  11. */
  12. public class TelaDeCadastro extends javax.swing.JDialog {
  13.  
  14. /**
  15. * Creates new form TelaDeCadastro
  16. */
  17. public TelaDeCadastro(java.awt.Frame parent, boolean modal) {
  18. super(parent, modal);
  19. initComponents();
  20. }
  21.  
  22. /**
  23. * This method is called from within the constructor to initialize the form.
  24. * WARNING: Do NOT modify this code. The content of this method is always
  25. * regenerated by the Form Editor.
  26. */
  27. @SuppressWarnings("unchecked")
  28. // <editor-fold defaultstate="collapsed" desc="Generated Code">
  29. private void initComponents() {
  30.  
  31. jPanel1 = new javax.swing.JPanel();
  32. razãosocial = new javax.swing.JTextField();
  33. endereço = new javax.swing.JTextField();
  34. complemento = new javax.swing.JTextField();
  35. bairro = new javax.swing.JTextField();
  36. cep = new javax.swing.JTextField();
  37. cidade = new javax.swing.JTextField();
  38. estado = new javax.swing.JComboBox<>();
  39. email = new javax.swing.JTextField();
  40. jLabel1 = new javax.swing.JLabel();
  41. jLabel2 = new javax.swing.JLabel();
  42. jLabel3 = new javax.swing.JLabel();
  43. jLabel4 = new javax.swing.JLabel();
  44. jLabel5 = new javax.swing.JLabel();
  45. jLabel6 = new javax.swing.JLabel();
  46. jLabel7 = new javax.swing.JLabel();
  47. jLabel8 = new javax.swing.JLabel();
  48. jLabel9 = new javax.swing.JLabel();
  49. jLabel10 = new javax.swing.JLabel();
  50. jLabel11 = new javax.swing.JLabel();
  51. telefone = new javax.swing.JFormattedTextField();
  52. cnpj = new javax.swing.JFormattedTextField();
  53. código = new javax.swing.JTextField();
  54. jPanel3 = new javax.swing.JPanel();
  55. botaolimpar = new javax.swing.JButton();
  56. botaoincluir = new javax.swing.JButton();
  57. botaofechar = new javax.swing.JButton();
  58.  
  59. setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
  60.  
  61. jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Dados do Fornecedor", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 11))); // NOI18N
  62.  
  63. razãosocial.addActionListener(new java.awt.event.ActionListener() {
  64. public void actionPerformed(java.awt.event.ActionEvent evt) {
  65. razãosocialActionPerformed(evt);
  66. }
  67. });
  68.  
  69. endereço.addActionListener(new java.awt.event.ActionListener() {
  70. public void actionPerformed(java.awt.event.ActionEvent evt) {
  71. endereçoActionPerformed(evt);
  72. }
  73. });
  74.  
  75. complemento.addActionListener(new java.awt.event.ActionListener() {
  76. public void actionPerformed(java.awt.event.ActionEvent evt) {
  77. complementoActionPerformed(evt);
  78. }
  79. });
  80.  
  81. bairro.addActionListener(new java.awt.event.ActionListener() {
  82. public void actionPerformed(java.awt.event.ActionEvent evt) {
  83. bairroActionPerformed(evt);
  84. }
  85. });
  86.  
  87. cep.addActionListener(new java.awt.event.ActionListener() {
  88. public void actionPerformed(java.awt.event.ActionEvent evt) {
  89. cepActionPerformed(evt);
  90. }
  91. });
  92.  
  93. cidade.addActionListener(new java.awt.event.ActionListener() {
  94. public void actionPerformed(java.awt.event.ActionEvent evt) {
  95. cidadeActionPerformed(evt);
  96. }
  97. });
  98.  
  99. estado.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "AC", "AM", "BA", "CE", "PR", "RJ", "SC", "SP", "RS" }));
  100. estado.addActionListener(new java.awt.event.ActionListener() {
  101. public void actionPerformed(java.awt.event.ActionEvent evt) {
  102. estadoActionPerformed(evt);
  103. }
  104. });
  105.  
  106. email.addActionListener(new java.awt.event.ActionListener() {
  107. public void actionPerformed(java.awt.event.ActionEvent evt) {
  108. emailActionPerformed(evt);
  109. }
  110. });
  111.  
  112. jLabel1.setFont(new java.awt.Font("Tahoma", 3, 11)); // NOI18N
  113. jLabel1.setText("Código:");
  114.  
  115. jLabel2.setFont(new java.awt.Font("Tahoma", 3, 11)); // NOI18N
  116. jLabel2.setText("Razão Social:");
  117.  
  118. jLabel3.setFont(new java.awt.Font("Tahoma", 3, 11)); // NOI18N
  119. jLabel3.setText("Endereço:");
  120.  
  121. jLabel4.setFont(new java.awt.Font("Tahoma", 3, 11)); // NOI18N
  122. jLabel4.setText("Complemento:");
  123.  
  124. jLabel5.setFont(new java.awt.Font("Tahoma", 3, 11)); // NOI18N
  125. jLabel5.setText("Bairro:");
  126.  
  127. jLabel6.setFont(new java.awt.Font("Tahoma", 3, 11)); // NOI18N
  128. jLabel6.setText("CEP:");
  129.  
  130. jLabel7.setFont(new java.awt.Font("Tahoma", 3, 11)); // NOI18N
  131. jLabel7.setText("Cidade:");
  132.  
  133. jLabel8.setFont(new java.awt.Font("Tahoma", 3, 11)); // NOI18N
  134. jLabel8.setText("Estado:");
  135.  
  136. jLabel9.setFont(new java.awt.Font("Tahoma", 3, 11)); // NOI18N
  137. jLabel9.setText("Telefone:");
  138.  
  139. jLabel10.setFont(new java.awt.Font("Tahoma", 3, 11)); // NOI18N
  140. jLabel10.setText("CNPJ:");
  141.  
  142. jLabel11.setFont(new java.awt.Font("Tahoma", 3, 11)); // NOI18N
  143. jLabel11.setText("E-mail");
  144.  
  145. try {
  146. telefone.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("(##)#####-####")));
  147. } catch (java.text.ParseException ex) {
  148. ex.printStackTrace();
  149. }
  150. telefone.addActionListener(new java.awt.event.ActionListener() {
  151. public void actionPerformed(java.awt.event.ActionEvent evt) {
  152. telefoneActionPerformed(evt);
  153. }
  154. });
  155.  
  156. try {
  157. cnpj.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("##.###.###/####-##")));
  158. } catch (java.text.ParseException ex) {
  159. ex.printStackTrace();
  160. }
  161. cnpj.addActionListener(new java.awt.event.ActionListener() {
  162. public void actionPerformed(java.awt.event.ActionEvent evt) {
  163. cnpjActionPerformed(evt);
  164. }
  165. });
  166.  
  167. código.addActionListener(new java.awt.event.ActionListener() {
  168. public void actionPerformed(java.awt.event.ActionEvent evt) {
  169. códigoActionPerformed(evt);
  170. }
  171. });
  172.  
  173. javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
  174. jPanel1.setLayout(jPanel1Layout);
  175. jPanel1Layout.setHorizontalGroup(
  176. jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  177. .addGroup(jPanel1Layout.createSequentialGroup()
  178. .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  179. .addComponent(jLabel1)
  180. .addComponent(código, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE))
  181. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  182. .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  183. .addGroup(jPanel1Layout.createSequentialGroup()
  184. .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)
  185. .addContainerGap())
  186. .addComponent(razãosocial)))
  187. .addGroup(jPanel1Layout.createSequentialGroup()
  188. .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  189. .addComponent(endereço, javax.swing.GroupLayout.PREFERRED_SIZE, 300, javax.swing.GroupLayout.PREFERRED_SIZE)
  190. .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE))
  191. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  192. .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  193. .addComponent(complemento, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)
  194. .addComponent(jLabel4))
  195. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  196. .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  197. .addComponent(bairro)
  198. .addGroup(jPanel1Layout.createSequentialGroup()
  199. .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
  200. .addGap(0, 74, Short.MAX_VALUE))))
  201. .addGroup(jPanel1Layout.createSequentialGroup()
  202. .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  203. .addComponent(cep)
  204. .addGroup(jPanel1Layout.createSequentialGroup()
  205. .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  206. .addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, 62, javax.swing.GroupLayout.PREFERRED_SIZE)
  207. .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE))
  208. .addGap(0, 0, Short.MAX_VALUE))
  209. .addComponent(telefone))
  210. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  211. .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  212. .addGroup(jPanel1Layout.createSequentialGroup()
  213. .addComponent(cnpj)
  214. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  215. .addComponent(email, javax.swing.GroupLayout.PREFERRED_SIZE, 301, javax.swing.GroupLayout.PREFERRED_SIZE))
  216. .addGroup(jPanel1Layout.createSequentialGroup()
  217. .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  218. .addGroup(jPanel1Layout.createSequentialGroup()
  219. .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
  220. .addGap(0, 347, Short.MAX_VALUE))
  221. .addComponent(cidade))
  222. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  223. .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
  224. .addComponent(estado, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  225. .addComponent(jLabel8, javax.swing.GroupLayout.DEFAULT_SIZE, 48, Short.MAX_VALUE))
  226. .addContainerGap())
  227. .addGroup(jPanel1Layout.createSequentialGroup()
  228. .addComponent(jLabel10, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
  229. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  230. .addComponent(jLabel11, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
  231. .addGap(246, 246, 246))))
  232. );
  233. jPanel1Layout.setVerticalGroup(
  234. jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  235. .addGroup(jPanel1Layout.createSequentialGroup()
  236. .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  237. .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  238. .addComponent(jLabel1)
  239. .addComponent(jLabel2))
  240. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  241. .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  242. .addComponent(razãosocial, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  243. .addComponent(código, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  244. .addGap(7, 7, 7)
  245. .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  246. .addComponent(jLabel3)
  247. .addComponent(jLabel4)
  248. .addComponent(jLabel5))
  249. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  250. .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  251. .addComponent(complemento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  252. .addComponent(bairro, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  253. .addComponent(endereço, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  254. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  255. .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  256. .addComponent(jLabel6)
  257. .addComponent(jLabel7)
  258. .addComponent(jLabel8))
  259. .addGap(4, 4, 4)
  260. .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  261. .addComponent(cep, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  262. .addComponent(cidade, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  263. .addComponent(estado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  264. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  265. .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  266. .addComponent(jLabel9)
  267. .addComponent(jLabel10)
  268. .addComponent(jLabel11))
  269. .addGap(4, 4, 4)
  270. .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  271. .addComponent(email, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  272. .addComponent(telefone, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  273. .addComponent(cnpj, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
  274. );
  275.  
  276. jPanel3.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(204, 204, 204)));
  277.  
  278. botaolimpar.setFont(new java.awt.Font("Tahoma", 2, 11)); // NOI18N
  279. botaolimpar.setText("Limpar");
  280.  
  281. botaoincluir.setFont(new java.awt.Font("Tahoma", 2, 11)); // NOI18N
  282. botaoincluir.setText("Incluir");
  283. botaoincluir.addActionListener(new java.awt.event.ActionListener() {
  284. public void actionPerformed(java.awt.event.ActionEvent evt) {
  285. botaoincluirActionPerformed(evt);
  286. }
  287. });
  288.  
  289. botaofechar.setFont(new java.awt.Font("Tahoma", 2, 11)); // NOI18N
  290. botaofechar.setText("Fechar");
  291. botaofechar.addActionListener(new java.awt.event.ActionListener() {
  292. public void actionPerformed(java.awt.event.ActionEvent evt) {
  293. botaofecharActionPerformed(evt);
  294. }
  295. });
  296.  
  297. javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
  298. jPanel3.setLayout(jPanel3Layout);
  299. jPanel3Layout.setHorizontalGroup(
  300. jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  301. .addGroup(jPanel3Layout.createSequentialGroup()
  302. .addContainerGap()
  303. .addComponent(botaolimpar, javax.swing.GroupLayout.PREFERRED_SIZE, 151, javax.swing.GroupLayout.PREFERRED_SIZE)
  304. .addGap(18, 18, 18)
  305. .addComponent(botaoincluir, javax.swing.GroupLayout.PREFERRED_SIZE, 169, javax.swing.GroupLayout.PREFERRED_SIZE)
  306. .addGap(18, 18, 18)
  307. .addComponent(botaofechar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  308. .addContainerGap())
  309. );
  310. jPanel3Layout.setVerticalGroup(
  311. jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  312. .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
  313. .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  314. .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  315. .addComponent(botaolimpar)
  316. .addComponent(botaoincluir)
  317. .addComponent(botaofechar))
  318. .addContainerGap())
  319. );
  320.  
  321. javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  322. getContentPane().setLayout(layout);
  323. layout.setHorizontalGroup(
  324. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  325. .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  326. .addComponent(jPanel3, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  327. );
  328. layout.setVerticalGroup(
  329. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  330. .addGroup(layout.createSequentialGroup()
  331. .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  332. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  333. .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  334. );
  335.  
  336. pack();
  337. }// </editor-fold>
  338.  
  339. private void endereçoActionPerformed(java.awt.event.ActionEvent evt) {
  340. complemento.requestFocus();
  341. }
  342.  
  343. private void estadoActionPerformed(java.awt.event.ActionEvent evt) {
  344. telefone.requestFocus();
  345. }
  346.  
  347. private void razãosocialActionPerformed(java.awt.event.ActionEvent evt) {
  348. endereço.requestFocus();
  349. }
  350.  
  351. private void códigoActionPerformed(java.awt.event.ActionEvent evt) {
  352. razãosocial.requestFocus(); // TODO add your handling code here:
  353. }
  354.  
  355. private void complementoActionPerformed(java.awt.event.ActionEvent evt) {
  356. bairro.requestFocus();
  357. }
  358.  
  359. private void bairroActionPerformed(java.awt.event.ActionEvent evt) {
  360. cep.requestFocus();
  361. }
  362.  
  363. private void cepActionPerformed(java.awt.event.ActionEvent evt) {
  364. cidade.requestFocus();
  365. }
  366.  
  367. private void cidadeActionPerformed(java.awt.event.ActionEvent evt) {
  368. estado.requestFocus();
  369. }
  370.  
  371. private void telefoneActionPerformed(java.awt.event.ActionEvent evt) {
  372. cnpj.requestFocus();
  373. }
  374.  
  375. private void cnpjActionPerformed(java.awt.event.ActionEvent evt) {
  376. email.requestFocus();
  377. }
  378.  
  379. private void emailActionPerformed(java.awt.event.ActionEvent evt) {
  380. // TODO add your handling code here:
  381. }
  382.  
  383. private void botaofecharActionPerformed(java.awt.event.ActionEvent evt) {
  384. setVisible(false); // TODO add your handling code here:
  385. }
  386.  
  387. private void botaoincluirActionPerformed(java.awt.event.ActionEvent evt) {
  388.  
  389. final String JDBC_DRIVER = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
  390. final String DB_URL = "jdbc:sqlserver://localhost:1434;databaseName=UniplacBD;user=sa;password=123"; //
  391.  
  392. Connection conn = null;
  393. Statement stmt = null;
  394. PreparedStatement pstmt = null;
  395.  
  396. try {
  397.  
  398. /**
  399. * ******** INICIO conectar ao banco *********
  400. */
  401. // Registra o driver JDBC e realiza a conexao
  402. Class.forName(JDBC_DRIVER);
  403. conn = DriverManager.getConnection(DB_URL);
  404. /**
  405. * ******** FIM conectar ao banco *********
  406. */
  407.  
  408. /**
  409. * ******** INICIO exemplo insert por prepareStatement *********
  410. */
  411. // cria um preparedStatement
  412. pstmt = conn.prepareStatement("insert into fornecedor (razaoSocial, endereco, complemento, bairro, cidade, estado, cep, telefone, eMail, cnpj) values (?,?,?,?,?,?,?,?,?,?)");
  413. // preenche os valores
  414. pstmt.setString(1, razãosocial.getText());
  415. pstmt.setString(2, endereço.getText());
  416. pstmt.setString(3, complemento.getText());
  417. pstmt.setString(4, bairro.getText());
  418. pstmt.setString(5, cidade.getText());
  419. pstmt.setString(6, (String)estado.getSelectedItem());
  420. pstmt.setString(7, cep.getText());
  421. pstmt.setString(8, telefone.getText());
  422. pstmt.setString(9, email.getText());
  423. pstmt.setString(10, cnpj.getText());
  424. // executa e fecha
  425. pstmt.execute();
  426. pstmt.close();
  427. /**
  428. * ******** FIM exemplo insert por prepareStatement *********
  429. */
  430.  
  431. //fecha a conexão com o banco de dados
  432. conn.close();
  433. } catch (SQLException se) {
  434. se.printStackTrace();
  435. } catch (Exception e) {
  436. e.printStackTrace();
  437. } finally {
  438. try {
  439. if (stmt != null) {
  440. stmt.close();
  441. }
  442. } catch (SQLException se2) {
  443. }
  444. try {
  445. if (conn != null) {
  446. conn.close();
  447. }
  448. } catch (SQLException se) {
  449. se.printStackTrace();
  450. }
  451. }
  452.  
  453. // TODO add your handling code here:
  454. }
  455.  
  456. /**
  457. * @param args the command line arguments
  458. */
  459. public static void main(String args[]) {
  460. /* Set the Nimbus look and feel */
  461. //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  462. /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
  463. * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  464. */
  465. try {
  466. for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  467. if ("Nimbus".equals(info.getName())) {
  468. javax.swing.UIManager.setLookAndFeel(info.getClassName());
  469. break;
  470. }
  471. }
  472. } catch (ClassNotFoundException ex) {
  473. java.util.logging.Logger.getLogger(TelaDeCadastro.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  474. } catch (InstantiationException ex) {
  475. java.util.logging.Logger.getLogger(TelaDeCadastro.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  476. } catch (IllegalAccessException ex) {
  477. java.util.logging.Logger.getLogger(TelaDeCadastro.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  478. } catch (javax.swing.UnsupportedLookAndFeelException ex) {
  479. java.util.logging.Logger.getLogger(TelaDeCadastro.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  480. }
  481. //</editor-fold>
  482.  
  483. /* Create and display the dialog */
  484. java.awt.EventQueue.invokeLater(new Runnable() {
  485. public void run() {
  486. TelaDeCadastro dialog = new TelaDeCadastro(new javax.swing.JFrame(), true);
  487. dialog.addWindowListener(new java.awt.event.WindowAdapter() {
  488. @Override
  489. public void windowClosing(java.awt.event.WindowEvent e) {
  490. System.exit(0);
  491. }
  492. });
  493. dialog.setVisible(true);
  494. }
  495. });
  496. }
  497.  
  498. // Variables declaration - do not modify
  499. private javax.swing.JTextField bairro;
  500. private javax.swing.JButton botaofechar;
  501. private javax.swing.JButton botaoincluir;
  502. private javax.swing.JButton botaolimpar;
  503. private javax.swing.JTextField cep;
  504. private javax.swing.JTextField cidade;
  505. private javax.swing.JFormattedTextField cnpj;
  506. private javax.swing.JTextField complemento;
  507. private javax.swing.JTextField código;
  508. private javax.swing.JTextField email;
  509. private javax.swing.JTextField endereço;
  510. private javax.swing.JComboBox<String> estado;
  511. private javax.swing.JLabel jLabel1;
  512. private javax.swing.JLabel jLabel10;
  513. private javax.swing.JLabel jLabel11;
  514. private javax.swing.JLabel jLabel2;
  515. private javax.swing.JLabel jLabel3;
  516. private javax.swing.JLabel jLabel4;
  517. private javax.swing.JLabel jLabel5;
  518. private javax.swing.JLabel jLabel6;
  519. private javax.swing.JLabel jLabel7;
  520. private javax.swing.JLabel jLabel8;
  521. private javax.swing.JLabel jLabel9;
  522. private javax.swing.JPanel jPanel1;
  523. private javax.swing.JPanel jPanel3;
  524. private javax.swing.JTextField razãosocial;
  525. private javax.swing.JFormattedTextField telefone;
  526. // End of variables declaration;
  527. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement