Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: JTable, Database

  1. #1
    Junior Member
    Join Date
    Oct 2017
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default JTable, Database

    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
    Last edited by domasbug1; October 14th, 2017 at 05:37 AM.

  2. #2
    Member
    Join Date
    Apr 2014
    Posts
    93
    Thanks
    3
    Thanked 7 Times in 7 Posts

    Default Re: JTable, Database

    model = new JTable();
    model.setModel((TableModel) model);
    final DefaultTableModel model = new DefaultTableModel
    You have a JTable named 'model' as well as a DefaultTableModel also named 'model'. I'm surprised you're able to compile and get that stacktrace (which is not complete) in the first place.

Similar Threads

  1. [SOLVED] JTable and database
    By Celsedada in forum What's Wrong With My Code?
    Replies: 3
    Last Post: December 26th, 2013, 06:07 AM
  2. Replies: 21
    Last Post: November 27th, 2012, 10:58 PM
  3. refreshing a jtable with database
    By kollyisrealisaac in forum JDBC & Databases
    Replies: 0
    Last Post: May 7th, 2011, 01:50 PM

Tags for this Thread