Hello guys, I just started to code and i got a problem with this code:
model = new JTable(); model.setModel((TableModel) model); final DefaultTableModel model = new DefaultTableModel(new String[]{"Vardas,Pavard\u0117", "\u012Emon\u0117", "Patik. Data", "Iki Data"}, 0); JButton perkrauti = new JButton("Perkrauti s\u0105ra\u0161\u0105."); perkrauti.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { Class.forName( "com.mysql.jdbc.Driver" ); Connection connection = DriverManager.getConnection("jdbc:mysql://ip/db","root", ""); String sql="SELECT * FROM db"; Statement st = connection.createStatement(); ResultSet rs = st.executeQuery(sql); while(rs.next()) { String vp = rs.getString("Vardas,Pavard\u0117"); String i = rs.getString("\u012Emon\u0117"); String pd = rs.getString("Patik. Data"); String id = rs.getString("Iki Data"); model.addRow(new Object[]{vp, i, pd, id}); } } catch (SQLException e1) { e1.printStackTrace(); } catch (ClassNotFoundException e1) { e1.printStackTrace(); } } });
I get error then i started this code.
Error:
at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source) at java.awt.EventQueue.dispatchEvent(Unknown Source) at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source) at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source) at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.run(Unknown Source)
I am trying to pick from database and add to JTable row. THanks for help