Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package tjee.banach_lukasz_okna;
- import java.sql.SQLException;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- /**
- *
- * @author student
- */
- public class Banach_lukasz_okna_apk extends javax.swing.JFrame {
- /**
- * Creates new form DbOkno
- */
- private boolean connect;
- private String out;
- private int id=100;
- public Banach_lukasz_okna_apk() {
- initComponents();
- jTextField1.setVisible(false);
- jTextField2.setVisible(false);
- jTextField3.setVisible(false);
- jTextField4.setVisible(false);
- jTextField5.setVisible(false);
- //jTextField6.setVisible(false);
- jB_dodaj.setVisible(false);
- }
- /**
- * This method is called from within the constructor to initialize the form.
- * WARNING: Do NOT modify this code. The content of this method is always
- * regenerated by the Form Editor.
- */
- @SuppressWarnings("unchecked")
- // <editor-fold defaultstate="collapsed" desc="Generated Code">
- private void initComponents() {
- jPanel1 = new javax.swing.JPanel();
- jScrollPane2 = new javax.swing.JScrollPane();
- jTable1 = new javax.swing.JTable();
- jB_Connect = new javax.swing.JButton();
- jB_Rozlacz = new javax.swing.JButton();
- jB_Wypisz = new javax.swing.JButton();
- jB_dodajUsera = new javax.swing.JButton();
- jTextField1 = new javax.swing.JTextField();
- jTextField2 = new javax.swing.JTextField();
- jB_dodaj = new javax.swing.JButton();
- jTextField3 = new javax.swing.JTextField();
- jTextField4 = new javax.swing.JTextField();
- jTextField5 = new javax.swing.JTextField();
- jCheckBox1 = new javax.swing.JCheckBox();
- jLabel1 = new javax.swing.JLabel();
- jScrollPane1 = new javax.swing.JScrollPane();
- jTextArea1 = new javax.swing.JTextArea();
- setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
- jTable1.setModel(new javax.swing.table.DefaultTableModel(
- new Object [][] {
- },
- new String [] {
- }
- ));
- jTable1.setColumnSelectionAllowed(true);
- jScrollPane2.setViewportView(jTable1);
- jTable1.getColumnModel().getSelectionModel().setSelectionMode(javax.swing.ListSelectionModel.SINGLE_INTERVAL_SELECTION);
- javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
- jPanel1.setLayout(jPanel1Layout);
- jPanel1Layout.setHorizontalGroup(
- jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addContainerGap()
- .addComponent(jScrollPane2))
- );
- jPanel1Layout.setVerticalGroup(
- jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 267, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addGap(0, 0, Short.MAX_VALUE))
- );
- jB_Connect.setText("Połącz");
- jB_Connect.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jB_ConnectActionPerformed(evt);
- }
- });
- jB_Rozlacz.setText("Rozłącz");
- jB_Rozlacz.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jB_RozlaczActionPerformed(evt);
- }
- });
- jB_Wypisz.setText("Wypisz");
- jB_Wypisz.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jB_WypiszActionPerformed(evt);
- }
- });
- jB_dodajUsera.setText("Dodaj usera");
- jB_dodajUsera.setActionCommand("Dodaj_Usera");
- jB_dodajUsera.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jB_dodajUseraActionPerformed(evt);
- }
- });
- jTextField1.addMouseListener(new java.awt.event.MouseAdapter() {
- public void mouseClicked(java.awt.event.MouseEvent evt) {
- jTextField1MouseClicked(evt);
- }
- });
- jTextField2.setToolTipText("");
- jTextField2.addMouseListener(new java.awt.event.MouseAdapter() {
- public void mouseClicked(java.awt.event.MouseEvent evt) {
- jTextField2MouseClicked(evt);
- }
- });
- jTextField2.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jTextField2ActionPerformed(evt);
- }
- });
- jB_dodaj.setText("Dodaj");
- jB_dodaj.setActionCommand("Dodaj_Usera");
- jB_dodaj.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jB_dodajActionPerformed(evt);
- }
- });
- jTextField3.setToolTipText("");
- jTextField3.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jTextField3ActionPerformed(evt);
- }
- });
- jTextField4.setToolTipText("");
- jTextField4.addMouseListener(new java.awt.event.MouseAdapter() {
- public void mouseClicked(java.awt.event.MouseEvent evt) {
- jTextField4MouseClicked(evt);
- }
- });
- jTextField4.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jTextField4ActionPerformed(evt);
- }
- });
- jTextField5.setToolTipText("");
- jTextField5.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jTextField5ActionPerformed(evt);
- }
- });
- jCheckBox1.setText("tak");
- jCheckBox1.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jCheckBox1ActionPerformed(evt);
- }
- });
- jLabel1.setText("Czy uchylne");
- jTextArea1.setColumns(20);
- jTextArea1.setRows(5);
- jScrollPane1.setViewportView(jTextArea1);
- javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
- getContentPane().setLayout(layout);
- layout.setHorizontalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
- .addContainerGap()
- .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
- .addGroup(layout.createSequentialGroup()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
- .addGroup(layout.createSequentialGroup()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
- .addGap(25, 25, 25)
- .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 260, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGroup(layout.createSequentialGroup()
- .addGap(39, 39, 39)
- .addComponent(jB_Connect)
- .addGap(20, 20, 20)
- .addComponent(jB_Rozlacz)
- .addGap(27, 27, 27)
- .addComponent(jB_Wypisz)))
- .addGap(32, 32, 32)
- .addComponent(jB_dodajUsera)
- .addGap(58, 58, 58))
- .addGroup(layout.createSequentialGroup()
- .addGap(25, 25, 25)
- .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 113, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addGap(18, 18, 18)
- .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
- .addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addComponent(jLabel1)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 130, Short.MAX_VALUE)
- .addComponent(jB_dodaj)
- .addGap(14, 14, 14))
- .addGroup(layout.createSequentialGroup()
- .addComponent(jCheckBox1)
- .addGap(0, 0, Short.MAX_VALUE)))))
- .addContainerGap())
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addGap(18, 18, 18)
- .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addGap(40, 40, 40)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jB_Connect)
- .addComponent(jB_Rozlacz)
- .addComponent(jB_Wypisz)
- .addComponent(jB_dodajUsera))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 6, Short.MAX_VALUE))
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
- .addComponent(jLabel1)
- .addComponent(jB_dodaj))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(jCheckBox1))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 6, Short.MAX_VALUE)
- .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE))
- );
- pack();
- }// </editor-fold>
- private void jB_ConnectActionPerformed(java.awt.event.ActionEvent evt) {
- try {
- connect = Banach_lukasz_okna.Connect();
- } catch (ClassNotFoundException | SQLException ex) {
- Logger.getLogger(Banach_lukasz_okna_apk.class.getName()).log(Level.SEVERE, null, ex);
- }
- if (connect) {
- jTextArea1.setText("Połączono");
- } else {
- jTextArea1.setText("Nie połączono");
- }// TODO add your handling code here:
- }
- private void jB_RozlaczActionPerformed(java.awt.event.ActionEvent evt) {
- try {
- connect = Banach_lukasz_okna.Disconnect();
- } catch (SQLException ex) {
- Logger.getLogger(Banach_lukasz_okna.class.getName()).log(Level.SEVERE, null, ex);
- }
- if (connect) {
- jTextArea1.setText("Rozłączono");
- } else {
- jTextArea1.setText("Nie rozłączono");
- }// TODO add your handling code here:// TODO add your handling code here:
- }
- private void jB_WypiszActionPerformed(java.awt.event.ActionEvent evt) {
- try {
- if (connect) {
- //String query="select * from BANACH_LUKASZ_OKNA_TB";
- out = Banach_lukasz_okna.getData();
- jTable1.setModel(Banach_lukasz_okna.getModel());
- jTextArea1.removeAll();
- jTextArea1.setText(out);
- //jTable1.set
- } else {
- jTextArea1.setText("Nie połączono");
- }
- } catch (SQLException ex) {
- Logger.getLogger(Banach_lukasz_okna.class.getName()).log(Level.SEVERE, null, ex);
- }
- // TODO add your handling code here:
- }
- private void jB_dodajUseraActionPerformed(java.awt.event.ActionEvent evt) {
- jB_Connect.setVisible(false);
- jB_Rozlacz.setVisible(false);
- jB_Wypisz.setVisible(false);
- jB_dodaj.setVisible(true);
- jTextField1.setVisible(true);
- jTextField2.setVisible(true);
- jTextField3.setVisible(true);
- jTextField4.setVisible(true);
- jTextField5.setVisible(true);
- //jTextField6.setVisible(true);
- jB_dodajUsera.setVisible(false);
- jTextField1.setText("producent");
- jTextField2.setText("typ");
- jTextField3.setText("material");
- jTextField4.setText("kolor");
- jTextField5.setText("grubosc_mm");
- //jTextField6.setText("kolor");
- try {
- if (connect) {
- out = Banach_lukasz_okna.getData();
- //jTextArea1.removeAll();
- //jTextArea1.setText(out);
- } else {
- //jTextArea1.setText("Nie połączono");
- }
- } catch (SQLException ex) {
- Logger.getLogger(Banach_lukasz_okna_apk.class.getName()).log(Level.SEVERE, null, ex);
- }
- // TODO add your handling code here:
- }
- private void jTextField2ActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- }
- private void jB_dodajActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- String send="Insert into app.pracownicy (imie,nazwisko,id) values(\'"+jTextField1.getText()+"\', \'"+jTextField2.getText()+"\', \'" + id + "\')";
- String QUERY = "INSERT INTO APP.BANACH_LUKASZ_OKNA_TB (PRODUCENT, TYP, MATERIAL, KOLOR, GRUBOSC_MM, CZY_UCHYLNE) values(";
- QUERY = QUERY + jTextField1.getText() + ",'" + jTextField2.getText() + ",'" + jTextField3.getText()+ ",'" + jTextField4.getText()+",'" + jTextField5.getText() +"')";
- try {
- if (connect) {
- //out = Banach_lukasz_okna.getData();
- jTextArea1.removeAll();
- jTextArea1.setText("Dodano usera");
- //DbManager.Sender(send);
- Banach_lukasz_okna.InsertInto(send);
- jTextArea1.setText(out);
- id++;
- akcja(evt);
- //jTextArea1.setText(out);
- } else {
- jTextArea1.setText("Nie udalo sie dodanie usera");
- akcja(evt);
- }
- } catch (SQLException ex) {
- Logger.getLogger(Banach_lukasz_okna_apk.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- private void jTextField3ActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- }
- private void jTextField4ActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- }
- private void jTextField5ActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- }
- private void jTextField4MouseClicked(java.awt.event.MouseEvent evt) {
- jTextField4.setText("");
- //jTextField4.set
- // TODO add your handling code here:
- }
- private void jTextField2MouseClicked(java.awt.event.MouseEvent evt) {
- // TODO add your handling code here:
- jTextField2.setText("");
- }
- private void jTextField1MouseClicked(java.awt.event.MouseEvent evt) {
- // TODO add your handling code here:
- jTextField1.setText("");
- }
- private void jCheckBox1ActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- }
- /*private void bSaveActionPerformed(java.awt.event.ActionEvent evt) {
- String QUERY = "insert into app.pracownicy(ID,NAZWISKO,IMIE)values(";
- QUERY = QUERY + jTextID.getText() + ",'" + jTextNazwisko.getText() + "','" + jTextImie.getText() + "')";
- try{
- DbManager.executeQuery(QUERY);
- }catch(SQLException ex){
- Logger.getLogger(DbOkno.class.getName()).log(Level.SEVERE, null, ex);
- }
- dAdd.setVisible(false);
- }*/
- private void akcja(java.awt.event.ActionEvent evt) {
- jB_Connect.setVisible(true);
- jB_Rozlacz.setVisible(true);
- jB_Wypisz.setVisible(true);
- jB_dodaj.setVisible(false);
- jTextField1.setVisible(false);
- jTextField2.setVisible(false);
- jTextField3.setVisible(false);
- jTextField4.setVisible(false);
- jTextField5.setVisible(false);
- //jTextField6.setVisible(false);
- jB_dodajUsera.setVisible(true);
- }
- public static void main(String args[]) {
- /* Set the Nimbus look and feel */
- //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
- /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
- * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
- */
- try {
- for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
- if ("Nimbus".equals(info.getName())) {
- javax.swing.UIManager.setLookAndFeel(info.getClassName());
- break;
- }
- }
- } catch (ClassNotFoundException ex) {
- java.util.logging.Logger.getLogger(Banach_lukasz_okna_apk.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (InstantiationException ex) {
- java.util.logging.Logger.getLogger(Banach_lukasz_okna_apk.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (IllegalAccessException ex) {
- java.util.logging.Logger.getLogger(Banach_lukasz_okna_apk.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (javax.swing.UnsupportedLookAndFeelException ex) {
- java.util.logging.Logger.getLogger(Banach_lukasz_okna_apk.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- }
- //</editor-fold>
- /* Create and display the form */
- java.awt.EventQueue.invokeLater(new Runnable() {
- public void run() {
- new Banach_lukasz_okna_apk().setVisible(true);
- }
- });
- }
- // Variables declaration - do not modify
- private javax.swing.JButton jB_Connect;
- private javax.swing.JButton jB_Rozlacz;
- private javax.swing.JButton jB_Wypisz;
- private javax.swing.JButton jB_dodaj;
- private javax.swing.JButton jB_dodajUsera;
- private javax.swing.JCheckBox jCheckBox1;
- private javax.swing.JLabel jLabel1;
- private javax.swing.JPanel jPanel1;
- private javax.swing.JScrollPane jScrollPane1;
- private javax.swing.JScrollPane jScrollPane2;
- private javax.swing.JTable jTable1;
- private javax.swing.JTextArea jTextArea1;
- private javax.swing.JTextField jTextField1;
- private javax.swing.JTextField jTextField2;
- private javax.swing.JTextField jTextField3;
- private javax.swing.JTextField jTextField4;
- private javax.swing.JTextField jTextField5;
- // End of variables declaration
- }
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package tjee.banach_lukasz_okna;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.ResultSetMetaData;
- import java.sql.SQLException;
- import java.sql.Statement;
- import java.util.Vector;
- import javax.swing.table.DefaultTableModel;
- /**
- *
- * @author łuk
- */
- public final class Banach_lukasz_okna {
- /**
- * @param args the command line arguments
- */
- public static final String DRIVER = "org.apache.derby.jdbc.EmbeddedDriver";
- public static final String JDBC_URL = "jdbc:derby:F:\\WAT\\SEM5\\java i apk\\lab1 prd\\Banach_lukasz_okna\\db\\banach_lukasz;user=admin";
- public static final String QUERY = "select * from app.BANACH_LUKASZ_OKNA_TB";
- private static java.sql.Connection conn;
- static void Sender(String send) {
- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
- }
- private Banach_lukasz_okna() {
- }
- public static boolean Connect() throws ClassNotFoundException, SQLException {
- conn = DriverManager.getConnection(JDBC_URL);
- if (conn == null) {
- return false;
- } else {
- return true;
- }//10
- }
- public static void executeQuery(String query) throws SQLException{
- Statement stat = conn.createStatement();
- stat.executeUpdate(query);
- }
- public static boolean Disconnect() throws SQLException {
- if (conn == null) {
- return false;
- } else {
- conn.close();
- return true;
- }
- }
- public static boolean InsertInto(String dane) throws SQLException{
- Statement st = conn.createStatement();//zapytanie
- if(conn==null){
- return false;
- }
- else{
- st.executeUpdate(dane);//
- return true;
- }
- }
- public static DefaultTableModel getModel() throws SQLException {
- String queryTable = "select * from app.BANACH_LUKASZ_OKNA_TB";
- Statement stat = conn.createStatement();
- PreparedStatement pat=conn.prepareStatement(queryTable);
- ResultSet rs = stat.executeQuery(queryTable);
- ResultSetMetaData rsmd = rs.getMetaData();
- String wiersz = new String();
- int colCount = rsmd.getColumnCount(); //ilosc kolumn
- DefaultTableModel dtm = new DefaultTableModel();
- Vector columns_name=new Vector();
- Vector data_rows=new Vector();
- /*for(int k=1;k<=colCount; k++){{
- columns_name.add(rsmd.getColumnName(k));
- }*/
- /*columns_name.add("id");
- columns_name.add("produkty");
- columns_name.add("typ");
- columns_name.add("material");
- columns_name.add("kolor");
- columns_name.add("grubosc[mm]");
- columns_name.add("czy uchylne");*/
- for(int i=1;i<=colCount; i++){
- //columns_name.addElement(rsmd.getCatalogName(i));
- columns_name.add(rsmd.getColumnName(i));
- }
- dtm.setColumnIdentifiers(columns_name);
- while(rs.next()){
- data_rows=new Vector();
- for(int j=1;j<=colCount;j++){
- data_rows.addElement(rs.getString(j));
- }
- dtm.addRow(data_rows);
- }
- //jTable1.setModel(dtm);
- return dtm;
- }
- public static String getData() throws SQLException {
- Statement stat = conn.createStatement();
- ResultSet rs = stat.executeQuery(QUERY);
- ResultSetMetaData rsmd = rs.getMetaData();
- String wiersz = new String();
- int colCount = rsmd.getColumnCount();
- for (int i = 1; i <= colCount; i++) {
- wiersz = wiersz.concat(rsmd.getColumnName(i) + " \t| ");
- }
- wiersz = wiersz.concat("\r\n");
- while (rs.next()) {
- System.out.println("");
- for (int i = 1; i <= colCount; i++) {
- wiersz = wiersz.concat(rs.getString(i) + " \t| ");
- }
- wiersz = wiersz.concat("\r\n");
- }
- if (stat != null) {
- stat.close();
- }
- return wiersz;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement