Advertisement
Guest User

Untitled

a guest
Nov 14th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 28.25 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package tjee.banach_lukasz_okna;
  7.  
  8. import java.sql.SQLException;
  9. import java.util.logging.Level;
  10. import java.util.logging.Logger;
  11.  
  12. /**
  13. *
  14. * @author student
  15. */
  16. public class Banach_lukasz_okna_apk extends javax.swing.JFrame {
  17.  
  18. /**
  19. * Creates new form DbOkno
  20. */
  21. private boolean connect;
  22. private String out;
  23. private int id=100;
  24.  
  25. public Banach_lukasz_okna_apk() {
  26. initComponents();
  27. jTextField1.setVisible(false);
  28. jTextField2.setVisible(false);
  29. jTextField3.setVisible(false);
  30. jTextField4.setVisible(false);
  31. jTextField5.setVisible(false);
  32. //jTextField6.setVisible(false);
  33.  
  34. jB_dodaj.setVisible(false);
  35. }
  36.  
  37. /**
  38. * This method is called from within the constructor to initialize the form.
  39. * WARNING: Do NOT modify this code. The content of this method is always
  40. * regenerated by the Form Editor.
  41. */
  42. @SuppressWarnings("unchecked")
  43. // <editor-fold defaultstate="collapsed" desc="Generated Code">
  44. private void initComponents() {
  45.  
  46. jPanel1 = new javax.swing.JPanel();
  47. jScrollPane2 = new javax.swing.JScrollPane();
  48. jTable1 = new javax.swing.JTable();
  49. jB_Connect = new javax.swing.JButton();
  50. jB_Rozlacz = new javax.swing.JButton();
  51. jB_Wypisz = new javax.swing.JButton();
  52. jB_dodajUsera = new javax.swing.JButton();
  53. jTextField1 = new javax.swing.JTextField();
  54. jTextField2 = new javax.swing.JTextField();
  55. jB_dodaj = new javax.swing.JButton();
  56. jTextField3 = new javax.swing.JTextField();
  57. jTextField4 = new javax.swing.JTextField();
  58. jTextField5 = new javax.swing.JTextField();
  59. jCheckBox1 = new javax.swing.JCheckBox();
  60. jLabel1 = new javax.swing.JLabel();
  61. jScrollPane1 = new javax.swing.JScrollPane();
  62. jTextArea1 = new javax.swing.JTextArea();
  63.  
  64. setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  65.  
  66. jTable1.setModel(new javax.swing.table.DefaultTableModel(
  67. new Object [][] {
  68.  
  69. },
  70. new String [] {
  71.  
  72. }
  73. ));
  74. jTable1.setColumnSelectionAllowed(true);
  75. jScrollPane2.setViewportView(jTable1);
  76. jTable1.getColumnModel().getSelectionModel().setSelectionMode(javax.swing.ListSelectionModel.SINGLE_INTERVAL_SELECTION);
  77.  
  78. javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
  79. jPanel1.setLayout(jPanel1Layout);
  80. jPanel1Layout.setHorizontalGroup(
  81. jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  82. .addGroup(jPanel1Layout.createSequentialGroup()
  83. .addContainerGap()
  84. .addComponent(jScrollPane2))
  85. );
  86. jPanel1Layout.setVerticalGroup(
  87. jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  88. .addGroup(jPanel1Layout.createSequentialGroup()
  89. .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 267, javax.swing.GroupLayout.PREFERRED_SIZE)
  90. .addGap(0, 0, Short.MAX_VALUE))
  91. );
  92.  
  93. jB_Connect.setText("Połącz");
  94. jB_Connect.addActionListener(new java.awt.event.ActionListener() {
  95. public void actionPerformed(java.awt.event.ActionEvent evt) {
  96. jB_ConnectActionPerformed(evt);
  97. }
  98. });
  99.  
  100. jB_Rozlacz.setText("Rozłącz");
  101. jB_Rozlacz.addActionListener(new java.awt.event.ActionListener() {
  102. public void actionPerformed(java.awt.event.ActionEvent evt) {
  103. jB_RozlaczActionPerformed(evt);
  104. }
  105. });
  106.  
  107. jB_Wypisz.setText("Wypisz");
  108. jB_Wypisz.addActionListener(new java.awt.event.ActionListener() {
  109. public void actionPerformed(java.awt.event.ActionEvent evt) {
  110. jB_WypiszActionPerformed(evt);
  111. }
  112. });
  113.  
  114. jB_dodajUsera.setText("Dodaj usera");
  115. jB_dodajUsera.setActionCommand("Dodaj_Usera");
  116. jB_dodajUsera.addActionListener(new java.awt.event.ActionListener() {
  117. public void actionPerformed(java.awt.event.ActionEvent evt) {
  118. jB_dodajUseraActionPerformed(evt);
  119. }
  120. });
  121.  
  122. jTextField1.addMouseListener(new java.awt.event.MouseAdapter() {
  123. public void mouseClicked(java.awt.event.MouseEvent evt) {
  124. jTextField1MouseClicked(evt);
  125. }
  126. });
  127.  
  128. jTextField2.setToolTipText("");
  129. jTextField2.addMouseListener(new java.awt.event.MouseAdapter() {
  130. public void mouseClicked(java.awt.event.MouseEvent evt) {
  131. jTextField2MouseClicked(evt);
  132. }
  133. });
  134. jTextField2.addActionListener(new java.awt.event.ActionListener() {
  135. public void actionPerformed(java.awt.event.ActionEvent evt) {
  136. jTextField2ActionPerformed(evt);
  137. }
  138. });
  139.  
  140. jB_dodaj.setText("Dodaj");
  141. jB_dodaj.setActionCommand("Dodaj_Usera");
  142. jB_dodaj.addActionListener(new java.awt.event.ActionListener() {
  143. public void actionPerformed(java.awt.event.ActionEvent evt) {
  144. jB_dodajActionPerformed(evt);
  145. }
  146. });
  147.  
  148. jTextField3.setToolTipText("");
  149. jTextField3.addActionListener(new java.awt.event.ActionListener() {
  150. public void actionPerformed(java.awt.event.ActionEvent evt) {
  151. jTextField3ActionPerformed(evt);
  152. }
  153. });
  154.  
  155. jTextField4.setToolTipText("");
  156. jTextField4.addMouseListener(new java.awt.event.MouseAdapter() {
  157. public void mouseClicked(java.awt.event.MouseEvent evt) {
  158. jTextField4MouseClicked(evt);
  159. }
  160. });
  161. jTextField4.addActionListener(new java.awt.event.ActionListener() {
  162. public void actionPerformed(java.awt.event.ActionEvent evt) {
  163. jTextField4ActionPerformed(evt);
  164. }
  165. });
  166.  
  167. jTextField5.setToolTipText("");
  168. jTextField5.addActionListener(new java.awt.event.ActionListener() {
  169. public void actionPerformed(java.awt.event.ActionEvent evt) {
  170. jTextField5ActionPerformed(evt);
  171. }
  172. });
  173.  
  174. jCheckBox1.setText("tak");
  175. jCheckBox1.addActionListener(new java.awt.event.ActionListener() {
  176. public void actionPerformed(java.awt.event.ActionEvent evt) {
  177. jCheckBox1ActionPerformed(evt);
  178. }
  179. });
  180.  
  181. jLabel1.setText("Czy uchylne");
  182.  
  183. jTextArea1.setColumns(20);
  184. jTextArea1.setRows(5);
  185. jScrollPane1.setViewportView(jTextArea1);
  186.  
  187. javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  188. getContentPane().setLayout(layout);
  189. layout.setHorizontalGroup(
  190. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  191. .addGroup(layout.createSequentialGroup()
  192. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  193. .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
  194. .addContainerGap()
  195. .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  196. .addGroup(layout.createSequentialGroup()
  197. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
  198. .addGroup(layout.createSequentialGroup()
  199. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  200. .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
  201. .addGap(25, 25, 25)
  202. .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 260, javax.swing.GroupLayout.PREFERRED_SIZE))
  203. .addGroup(layout.createSequentialGroup()
  204. .addGap(39, 39, 39)
  205. .addComponent(jB_Connect)
  206. .addGap(20, 20, 20)
  207. .addComponent(jB_Rozlacz)
  208. .addGap(27, 27, 27)
  209. .addComponent(jB_Wypisz)))
  210. .addGap(32, 32, 32)
  211. .addComponent(jB_dodajUsera)
  212. .addGap(58, 58, 58))
  213. .addGroup(layout.createSequentialGroup()
  214. .addGap(25, 25, 25)
  215. .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 113, javax.swing.GroupLayout.PREFERRED_SIZE)
  216. .addGap(18, 18, 18)
  217. .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE)
  218. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  219. .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)
  220. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  221. .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)
  222. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
  223. .addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)
  224. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  225. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  226. .addGroup(layout.createSequentialGroup()
  227. .addComponent(jLabel1)
  228. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 130, Short.MAX_VALUE)
  229. .addComponent(jB_dodaj)
  230. .addGap(14, 14, 14))
  231. .addGroup(layout.createSequentialGroup()
  232. .addComponent(jCheckBox1)
  233. .addGap(0, 0, Short.MAX_VALUE)))))
  234. .addContainerGap())
  235. );
  236. layout.setVerticalGroup(
  237. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  238. .addGroup(layout.createSequentialGroup()
  239. .addGap(18, 18, 18)
  240. .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  241. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  242. .addGroup(layout.createSequentialGroup()
  243. .addGap(40, 40, 40)
  244. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  245. .addComponent(jB_Connect)
  246. .addComponent(jB_Rozlacz)
  247. .addComponent(jB_Wypisz)
  248. .addComponent(jB_dodajUsera))
  249. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 6, Short.MAX_VALUE))
  250. .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
  251. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  252. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
  253. .addComponent(jLabel1)
  254. .addComponent(jB_dodaj))
  255. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
  256. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  257. .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  258. .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  259. .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  260. .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  261. .addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  262. .addComponent(jCheckBox1))
  263. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 6, Short.MAX_VALUE)
  264. .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE))
  265. );
  266.  
  267. pack();
  268. }// </editor-fold>
  269.  
  270. private void jB_ConnectActionPerformed(java.awt.event.ActionEvent evt) {
  271. try {
  272. connect = Banach_lukasz_okna.Connect();
  273. } catch (ClassNotFoundException | SQLException ex) {
  274. Logger.getLogger(Banach_lukasz_okna_apk.class.getName()).log(Level.SEVERE, null, ex);
  275. }
  276. if (connect) {
  277. jTextArea1.setText("Połączono");
  278. } else {
  279. jTextArea1.setText("Nie połączono");
  280. }// TODO add your handling code here:
  281. }
  282.  
  283. private void jB_RozlaczActionPerformed(java.awt.event.ActionEvent evt) {
  284. try {
  285. connect = Banach_lukasz_okna.Disconnect();
  286. } catch (SQLException ex) {
  287. Logger.getLogger(Banach_lukasz_okna.class.getName()).log(Level.SEVERE, null, ex);
  288. }
  289. if (connect) {
  290. jTextArea1.setText("Rozłączono");
  291. } else {
  292. jTextArea1.setText("Nie rozłączono");
  293. }// TODO add your handling code here:// TODO add your handling code here:
  294. }
  295.  
  296. private void jB_WypiszActionPerformed(java.awt.event.ActionEvent evt) {
  297. try {
  298. if (connect) {
  299. //String query="select * from BANACH_LUKASZ_OKNA_TB";
  300. out = Banach_lukasz_okna.getData();
  301. jTable1.setModel(Banach_lukasz_okna.getModel());
  302.  
  303. jTextArea1.removeAll();
  304. jTextArea1.setText(out);
  305. //jTable1.set
  306. } else {
  307. jTextArea1.setText("Nie połączono");
  308. }
  309. } catch (SQLException ex) {
  310. Logger.getLogger(Banach_lukasz_okna.class.getName()).log(Level.SEVERE, null, ex);
  311. }
  312. // TODO add your handling code here:
  313. }
  314.  
  315. private void jB_dodajUseraActionPerformed(java.awt.event.ActionEvent evt) {
  316. jB_Connect.setVisible(false);
  317. jB_Rozlacz.setVisible(false);
  318. jB_Wypisz.setVisible(false);
  319. jB_dodaj.setVisible(true);
  320. jTextField1.setVisible(true);
  321. jTextField2.setVisible(true);
  322. jTextField3.setVisible(true);
  323. jTextField4.setVisible(true);
  324. jTextField5.setVisible(true);
  325. //jTextField6.setVisible(true);
  326.  
  327. jB_dodajUsera.setVisible(false);
  328. jTextField1.setText("producent");
  329. jTextField2.setText("typ");
  330. jTextField3.setText("material");
  331. jTextField4.setText("kolor");
  332. jTextField5.setText("grubosc_mm");
  333. //jTextField6.setText("kolor");
  334.  
  335.  
  336.  
  337. try {
  338. if (connect) {
  339. out = Banach_lukasz_okna.getData();
  340. //jTextArea1.removeAll();
  341. //jTextArea1.setText(out);
  342. } else {
  343. //jTextArea1.setText("Nie połączono");
  344. }
  345. } catch (SQLException ex) {
  346. Logger.getLogger(Banach_lukasz_okna_apk.class.getName()).log(Level.SEVERE, null, ex);
  347. }
  348. // TODO add your handling code here:
  349. }
  350.  
  351. private void jTextField2ActionPerformed(java.awt.event.ActionEvent evt) {
  352. // TODO add your handling code here:
  353. }
  354.  
  355. private void jB_dodajActionPerformed(java.awt.event.ActionEvent evt) {
  356. // TODO add your handling code here:
  357.  
  358. String send="Insert into app.pracownicy (imie,nazwisko,id) values(\'"+jTextField1.getText()+"\', \'"+jTextField2.getText()+"\', \'" + id + "\')";
  359. String QUERY = "INSERT INTO APP.BANACH_LUKASZ_OKNA_TB (PRODUCENT, TYP, MATERIAL, KOLOR, GRUBOSC_MM, CZY_UCHYLNE) values(";
  360. QUERY = QUERY + jTextField1.getText() + ",'" + jTextField2.getText() + ",'" + jTextField3.getText()+ ",'" + jTextField4.getText()+",'" + jTextField5.getText() +"')";
  361. try {
  362. if (connect) {
  363. //out = Banach_lukasz_okna.getData();
  364. jTextArea1.removeAll();
  365. jTextArea1.setText("Dodano usera");
  366. //DbManager.Sender(send);
  367. Banach_lukasz_okna.InsertInto(send);
  368. jTextArea1.setText(out);
  369. id++;
  370. akcja(evt);
  371. //jTextArea1.setText(out);
  372. } else {
  373. jTextArea1.setText("Nie udalo sie dodanie usera");
  374. akcja(evt);
  375. }
  376. } catch (SQLException ex) {
  377. Logger.getLogger(Banach_lukasz_okna_apk.class.getName()).log(Level.SEVERE, null, ex);
  378. }
  379.  
  380. }
  381.  
  382. private void jTextField3ActionPerformed(java.awt.event.ActionEvent evt) {
  383. // TODO add your handling code here:
  384. }
  385.  
  386. private void jTextField4ActionPerformed(java.awt.event.ActionEvent evt) {
  387. // TODO add your handling code here:
  388. }
  389.  
  390. private void jTextField5ActionPerformed(java.awt.event.ActionEvent evt) {
  391. // TODO add your handling code here:
  392. }
  393.  
  394. private void jTextField4MouseClicked(java.awt.event.MouseEvent evt) {
  395. jTextField4.setText("");
  396. //jTextField4.set
  397. // TODO add your handling code here:
  398. }
  399.  
  400. private void jTextField2MouseClicked(java.awt.event.MouseEvent evt) {
  401. // TODO add your handling code here:
  402. jTextField2.setText("");
  403. }
  404.  
  405. private void jTextField1MouseClicked(java.awt.event.MouseEvent evt) {
  406. // TODO add your handling code here:
  407. jTextField1.setText("");
  408. }
  409.  
  410. private void jCheckBox1ActionPerformed(java.awt.event.ActionEvent evt) {
  411. // TODO add your handling code here:
  412. }
  413.  
  414. /*private void bSaveActionPerformed(java.awt.event.ActionEvent evt) {
  415. String QUERY = "insert into app.pracownicy(ID,NAZWISKO,IMIE)values(";
  416. QUERY = QUERY + jTextID.getText() + ",'" + jTextNazwisko.getText() + "','" + jTextImie.getText() + "')";
  417. try{
  418. DbManager.executeQuery(QUERY);
  419. }catch(SQLException ex){
  420. Logger.getLogger(DbOkno.class.getName()).log(Level.SEVERE, null, ex);
  421. }
  422. dAdd.setVisible(false);
  423. }*/
  424.  
  425. private void akcja(java.awt.event.ActionEvent evt) {
  426. jB_Connect.setVisible(true);
  427. jB_Rozlacz.setVisible(true);
  428. jB_Wypisz.setVisible(true);
  429. jB_dodaj.setVisible(false);
  430. jTextField1.setVisible(false);
  431. jTextField2.setVisible(false);
  432. jTextField3.setVisible(false);
  433. jTextField4.setVisible(false);
  434. jTextField5.setVisible(false);
  435. //jTextField6.setVisible(false);
  436.  
  437.  
  438. jB_dodajUsera.setVisible(true);
  439. }
  440.  
  441.  
  442. public static void main(String args[]) {
  443. /* Set the Nimbus look and feel */
  444. //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  445. /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
  446. * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  447. */
  448. try {
  449. for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  450. if ("Nimbus".equals(info.getName())) {
  451. javax.swing.UIManager.setLookAndFeel(info.getClassName());
  452. break;
  453. }
  454. }
  455. } catch (ClassNotFoundException ex) {
  456. java.util.logging.Logger.getLogger(Banach_lukasz_okna_apk.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  457. } catch (InstantiationException ex) {
  458. java.util.logging.Logger.getLogger(Banach_lukasz_okna_apk.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  459. } catch (IllegalAccessException ex) {
  460. java.util.logging.Logger.getLogger(Banach_lukasz_okna_apk.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  461. } catch (javax.swing.UnsupportedLookAndFeelException ex) {
  462. java.util.logging.Logger.getLogger(Banach_lukasz_okna_apk.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  463. }
  464. //</editor-fold>
  465.  
  466. /* Create and display the form */
  467. java.awt.EventQueue.invokeLater(new Runnable() {
  468. public void run() {
  469. new Banach_lukasz_okna_apk().setVisible(true);
  470. }
  471. });
  472. }
  473.  
  474.  
  475. // Variables declaration - do not modify
  476. private javax.swing.JButton jB_Connect;
  477. private javax.swing.JButton jB_Rozlacz;
  478. private javax.swing.JButton jB_Wypisz;
  479. private javax.swing.JButton jB_dodaj;
  480. private javax.swing.JButton jB_dodajUsera;
  481. private javax.swing.JCheckBox jCheckBox1;
  482. private javax.swing.JLabel jLabel1;
  483. private javax.swing.JPanel jPanel1;
  484. private javax.swing.JScrollPane jScrollPane1;
  485. private javax.swing.JScrollPane jScrollPane2;
  486. private javax.swing.JTable jTable1;
  487. private javax.swing.JTextArea jTextArea1;
  488. private javax.swing.JTextField jTextField1;
  489. private javax.swing.JTextField jTextField2;
  490. private javax.swing.JTextField jTextField3;
  491. private javax.swing.JTextField jTextField4;
  492. private javax.swing.JTextField jTextField5;
  493. // End of variables declaration
  494. }
  495.  
  496.  
  497.  
  498.  
  499. /*
  500. * To change this license header, choose License Headers in Project Properties.
  501. * To change this template file, choose Tools | Templates
  502. * and open the template in the editor.
  503. */
  504. package tjee.banach_lukasz_okna;
  505.  
  506. import java.sql.DriverManager;
  507. import java.sql.PreparedStatement;
  508. import java.sql.ResultSet;
  509. import java.sql.ResultSetMetaData;
  510. import java.sql.SQLException;
  511. import java.sql.Statement;
  512. import java.util.Vector;
  513. import javax.swing.table.DefaultTableModel;
  514.  
  515. /**
  516. *
  517. * @author łuk
  518. */
  519. public final class Banach_lukasz_okna {
  520.  
  521. /**
  522. * @param args the command line arguments
  523. */
  524. public static final String DRIVER = "org.apache.derby.jdbc.EmbeddedDriver";
  525. public static final String JDBC_URL = "jdbc:derby:F:\\WAT\\SEM5\\java i apk\\lab1 prd\\Banach_lukasz_okna\\db\\banach_lukasz;user=admin";
  526. public static final String QUERY = "select * from app.BANACH_LUKASZ_OKNA_TB";
  527. private static java.sql.Connection conn;
  528.  
  529. static void Sender(String send) {
  530. throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
  531. }
  532.  
  533. private Banach_lukasz_okna() {
  534. }
  535.  
  536. public static boolean Connect() throws ClassNotFoundException, SQLException {
  537. conn = DriverManager.getConnection(JDBC_URL);
  538. if (conn == null) {
  539. return false;
  540. } else {
  541. return true;
  542. }//10
  543. }
  544.  
  545. public static void executeQuery(String query) throws SQLException{
  546. Statement stat = conn.createStatement();
  547. stat.executeUpdate(query);
  548. }
  549.  
  550. public static boolean Disconnect() throws SQLException {
  551. if (conn == null) {
  552. return false;
  553. } else {
  554. conn.close();
  555. return true;
  556. }
  557. }
  558.  
  559. public static boolean InsertInto(String dane) throws SQLException{
  560. Statement st = conn.createStatement();//zapytanie
  561. if(conn==null){
  562. return false;
  563. }
  564. else{
  565. st.executeUpdate(dane);//
  566. return true;
  567. }
  568. }
  569.  
  570. public static DefaultTableModel getModel() throws SQLException {
  571. String queryTable = "select * from app.BANACH_LUKASZ_OKNA_TB";
  572. Statement stat = conn.createStatement();
  573. PreparedStatement pat=conn.prepareStatement(queryTable);
  574. ResultSet rs = stat.executeQuery(queryTable);
  575. ResultSetMetaData rsmd = rs.getMetaData();
  576. String wiersz = new String();
  577. int colCount = rsmd.getColumnCount(); //ilosc kolumn
  578. DefaultTableModel dtm = new DefaultTableModel();
  579. Vector columns_name=new Vector();
  580. Vector data_rows=new Vector();
  581.  
  582. /*for(int k=1;k<=colCount; k++){{
  583. columns_name.add(rsmd.getColumnName(k));
  584. }*/
  585. /*columns_name.add("id");
  586. columns_name.add("produkty");
  587. columns_name.add("typ");
  588. columns_name.add("material");
  589. columns_name.add("kolor");
  590. columns_name.add("grubosc[mm]");
  591. columns_name.add("czy uchylne");*/
  592. for(int i=1;i<=colCount; i++){
  593. //columns_name.addElement(rsmd.getCatalogName(i));
  594. columns_name.add(rsmd.getColumnName(i));
  595. }
  596. dtm.setColumnIdentifiers(columns_name);
  597.  
  598. while(rs.next()){
  599. data_rows=new Vector();
  600. for(int j=1;j<=colCount;j++){
  601. data_rows.addElement(rs.getString(j));
  602. }
  603. dtm.addRow(data_rows);
  604. }
  605. //jTable1.setModel(dtm);
  606.  
  607. return dtm;
  608. }
  609. public static String getData() throws SQLException {
  610. Statement stat = conn.createStatement();
  611. ResultSet rs = stat.executeQuery(QUERY);
  612. ResultSetMetaData rsmd = rs.getMetaData();
  613. String wiersz = new String();
  614. int colCount = rsmd.getColumnCount();
  615. for (int i = 1; i <= colCount; i++) {
  616. wiersz = wiersz.concat(rsmd.getColumnName(i) + " \t| ");
  617. }
  618. wiersz = wiersz.concat("\r\n");
  619. while (rs.next()) {
  620. System.out.println("");
  621. for (int i = 1; i <= colCount; i++) {
  622. wiersz = wiersz.concat(rs.getString(i) + " \t| ");
  623. }
  624. wiersz = wiersz.concat("\r\n");
  625. }
  626. if (stat != null) {
  627. stat.close();
  628. }
  629. return wiersz;
  630. }
  631.  
  632. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement