9 Replies - 718 Views - Last Post: 11 April 2012 - 08:59 PM Rate Topic: -----

#1 Silent Ace  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 42
  • Joined: 07-January 09

Table query errors after adding new row

Posted 11 April 2012 - 06:07 PM

I want to create a simple app for a database where you can add new contacts and so far i have one class for the main window and some methods and another one for the connection and getting the table column names and data. The app is "working", but i am getting a lot of errors when pressed the add button. These are the methods in the connection class
//get the query to execute
	public ResultSet setQuery(String query){
		try{
			statement.getConnection().createStatement();
			resultSet = statement.executeQuery(query);
		}
		catch(Exception ex){
			ex.printStackTrace();
		}
		return resultSet;
	};
	
	//get the name of the columns from the database
	public static String[] getColumnNames(ResultSet resultSet){
		String[] columnNames = null;
		
		try{
			resultSetMetaData = resultSet.getMetaData();
			columnNames = new String[resultSetMetaData.getColumnCount()];
			int columnNumber = resultSetMetaData.getColumnCount();
			for(int i = 0; i < columnNumber; i++){
				columnNames[i] = resultSetMetaData.getColumnLabel(i + 1);
			}
		}
		catch (Exception e){
			e.printStackTrace();
		}
		return columnNames;
	};
	
	//get the table data 
	public static Object[][] getTableData(ResultSet resultSet){
		List<Object> data = new ArrayList<Object>();
		try{
			int columnNumber = resultSet.getMetaData().getColumnCount();
			
			while(resultSet.next()){
				Object[] tableData = new Object[columnNumber];
				for(int i = 0; i < tableData.length; i++){
					tableData[i] = resultSet.getObject(i + 1);
				}
				data.add(tableData);
			}
		}



The methos for displaying the table is in the main class
public static TableModel displayTable(String query) {
		
        TableModel tableModel;
        try {  
           JDBCConnection jdbc = new JDBCConnection("jdbc:postgresql://localhost:5678/DDD", 
					"postgres", "portal");
           ResultSet resultSet = jdbc.setQuery(query);
          
           tableModel = new DefaultTableModel
        		   (jdbc.getTableData(resultSet), jdbc.getColumnNames(resultSet));     
        } catch(Exception e) {  
           throw new RuntimeException(e); 
        }  
        return tableModel;
     }



And to display the table in the window i call the Jtable masterTable in the constructior like this
masterTable = new JTable(displayTable("select * from phonebook"));



For adding the new contact information in the database i call this method:
public void addTableData(){
		displayTable("INSERT INTO phonebook VALUES ('"
				+ nameTextField.getText()+ "','" + lastNameTextField.getText() + "','" 
				+ addressTextField.getText()+ "','" + phoneTextField.getText()+ "')");
		
		//after sending set the text field to null text 
		nameTextField.setText("");
		lastNameTextField.setText("");
		addressTextField.setText("");
		phoneTextField.setText("");
	}



And adding this method to the button listener:
addButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				addTableData();
			}
		});



There are two problems. First the there are a lot of errors

org.postgresql.util.PSQLException: No results were returned by the query.
	at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:255)
	at app.JDBCConnection.setQuery(JDBCConnection.java:73)
	at app.TestClass.displayTable(TestClass.java:144)
	at app.TestClass.addTableData(TestClass.java:126)
	at app.TestClass$1.actionPerformed(TestClass.java:80)


java.lang.NullPointerException
	at app.JDBCConnection.getTableData(JDBCConnection.java:103)
	at app.TestClass.displayTable(TestClass.java:147)
	at app.TestClass.addTableData(TestClass.java:126)
	at app.TestClass$1.actionPerformed(TestClass.java:80)


java.lang.NullPointerException
	at app.JDBCConnection.getColumnNames(JDBCConnection.java:86)
	at app.TestClass.displayTable(TestClass.java:147)
	at app.TestClass.addTableData(TestClass.java:126)
	at app.TestClass$1.actionPerformed(TestClass.java:80)



I know that the resultSet is null hence the errors above, and that it has to do something with the return of the table. The second problem is that the table does not refresh itself after adding the info of the new contact, but only after closing and reopening the application. Some method like repaint(), or fire() will probably solve this. Thanks for your help.

Is This A Good Question/Topic? 0
  • +

Replies To: Table query errors after adding new row

#2 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8334
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Table query errors after adding new row

Posted 11 April 2012 - 06:23 PM

Please post your whole code, with the import statements, so we can match the line numbers displayed in the stack trace like

at app.TestClass.displayTable(TestClass.java:144)

with the actual line of code in your code in TestClass line 144
Was This Post Helpful? 0
  • +
  • -

#3 Silent Ace  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 42
  • Joined: 07-January 09

Re: Table query errors after adding new row

Posted 11 April 2012 - 06:54 PM

Sure :)

My main test class
package app;

import java.awt.EventQueue;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.sql.ResultSet;
import java.util.EventListener;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.ListSelectionModel;
import javax.swing.UIManager;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;

import org.apache.poi.ss.util.CellReference.NameType;

public class TestClass extends JFrame{
	
	private JPanel masterPanel;
	private JTable masterTable;
	private JScrollPane masterScrollPane;
	private JLabel nameLabel, lastLabel, addressLabel, phoneLabel;
	private static JTextField nameTextField;
	private static JTextField lastNameTextField;
	private static JTextField addressTextField;
	private static JTextField phoneTextField;
	private JButton addButton, deleteButton, searchButton, createReportButton;
	private JComboBox reportComboBox;

	public TestClass(){
		setDefaultCloseOperation(EXIT_ON_CLOSE);
		setSize(600, 450);
		masterPanel = new JPanel();
		masterPanel.setLayout(null);
		
		nameLabel = new JLabel("FirstName:");
		nameLabel.setFont(new Font("SansSerif", Font.PLAIN, 15));
		nameLabel.setBounds(25, 275, 75, 30);
		masterPanel.add(nameLabel);
		lastLabel = new JLabel("LastName:");
		lastLabel.setFont(new Font("SansSerif", Font.PLAIN, 15));
		lastLabel.setBounds(25, 300, 75, 30);
		addressLabel = new JLabel("Street address:");
		addressLabel.setFont(new Font("SansSerif", Font.PLAIN, 15));
		addressLabel.setBounds(25, 325, 100, 30);
		phoneLabel = new JLabel("Phone number:");
		phoneLabel.setFont(new Font("SansSerif", Font.PLAIN, 15));
		phoneLabel.setBounds(25, 350, 100, 30);
		
		nameTextField = new JTextField();
		nameTextField.setFont(new Font("SansSerif", Font.PLAIN, 15));
		nameTextField.setBounds(130, 278, 320, 22);
		lastNameTextField = new JTextField();
		lastNameTextField.setFont(new Font("SansSerif", Font.PLAIN, 15));
		lastNameTextField.setBounds(130, 303, 320, 22);
		addressTextField = new JTextField();
		addressTextField.setFont(new Font("SansSerif", Font.PLAIN, 15));
		addressTextField.setBounds(130, 328, 320, 22);
		phoneTextField = new JTextField();
		phoneTextField.setFont(new Font("SansSerif", Font.PLAIN, 15));
		phoneTextField.setBounds(130, 353, 320, 22);
		
		addButton = new JButton("Add");
		addButton.setFont(new Font("SansSerif", Font.PLAIN, 15));
		addButton.setBounds(460, 277, 100, 25);
		addButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				addTableData();
			}
		});
		
		deleteButton = new JButton("Delete");
		deleteButton.setFont(new Font("SansSerif", Font.PLAIN, 15));
		deleteButton.setBounds(460, 302, 100, 25);
		searchButton = new JButton("Search");
		searchButton.setFont(new Font("SansSerif", Font.PLAIN, 15));
		searchButton.setBounds(460, 328, 100, 25);
		createReportButton = new JButton("Create");
		createReportButton.setFont(new Font("SansSerif", Font.PLAIN, 15));
		createReportButton.setBounds(460, 353, 100, 25);
		
		String[] choise = {"Report As","PDF","XML","HTML","Excel", "Word"};
		reportComboBox = new JComboBox(choise);
		reportComboBox.setFont(new Font("SansSerif", Font.PLAIN, 15));
		reportComboBox.setEditable(false);
		reportComboBox.setBounds(461, 380, 100, 25);
		
		masterTable = new JTable(displayTable("select * from phonebook"));
		masterTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
		masterTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
		//masterTable.revalidate();
		masterScrollPane = new JScrollPane(masterTable);
		masterScrollPane.setBounds(26, 20, 530, 231);
			
		masterPanel.add(masterScrollPane);
		masterPanel.add(nameLabel);
		masterPanel.add(nameTextField);
		masterPanel.add(lastLabel);
		masterPanel.add(lastNameTextField);
		masterPanel.add(addressLabel);
		masterPanel.add(addressTextField);
		masterPanel.add(phoneLabel);
		masterPanel.add(phoneTextField);
		masterPanel.add(addButton);
		masterPanel.add(deleteButton);
		masterPanel.add(searchButton);
		masterPanel.add(createReportButton);
		masterPanel.add(reportComboBox);
		
		add(masterPanel);
	}
	
	public void addTableData(){
		displayTable("INSERT INTO phonebook VALUES ('"
				+ nameTextField.getText()+ "','" + lastNameTextField.getText() + "','" 
				+ addressTextField.getText()+ "','" + phoneTextField.getText()+ "')");
		
		//after sending set the text field to null text 
		nameTextField.setText("");
		lastNameTextField.setText("");
		addressTextField.setText("");
		phoneTextField.setText("");
	}
	
	//display the tableModel (connection, query, class call)
	public static TableModel displayTable(String query) {
		
        TableModel tableModel;
        try {  
           JDBCConnection jdbc = new JDBCConnection("jdbc:postgresql://localhost:5678/DDD", 
					"postgres", "portal");
           ResultSet resultSet = jdbc.setQuery(query);
          
           tableModel = new DefaultTableModel
        		   (jdbc.getTableData(resultSet), jdbc.getColumnNames(resultSet));     
        } catch(Exception e) {  
           throw new RuntimeException(e); 
        }  
        return tableModel;
     }
	
	public static void main(String[] args) {
		try {
			UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
		} catch (Throwable e) {
			e.printStackTrace();
		}
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					TestClass frame = new TestClass();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}
}



The connection class

package app;

import java.util.List;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;

public class JDBCConnection {
	
	private Connection connection = null;
	private Statement statement = null;
	private ResultSet resultSet = null;
	private static ResultSetMetaData resultSetMetaData = null;

	private String userName;
	private String password;
	private String host_name;
	
	public JDBCConnection(String host, String user_name, String password_con) throws SQLException{
		this.userName = user_name;
		this.password = password_con;
		this.host_name = host;
		
		try {
			Class.forName("org.postgresql.Driver");
			try {
				connection = DriverManager.getConnection(host_name, userName, password);
				statement = connection.createStatement();
				
			}
			
			catch (Throwable connection){
				connection.printStackTrace();
				statement.close();
				System.out.println("statement closed");
			}
			finally{
				try{
					if(statement != null){
						//statement.close();
						System.out.println("try statement closed");
					}
				}
				catch(Exception errorStatement){
					errorStatement.printStackTrace();
				}
				
				try{
					if(connection != null){
						//connection.close();
						System.out.println("try connection closed");
					}
				}
				catch(Exception errorConnection){
					errorConnection.printStackTrace();
				}
			}
		}
		catch(ClassNotFoundException driverProblem){
			driverProblem.printStackTrace();
		}
	};	
	
	//get the query to execute
	public ResultSet setQuery(String query){
		try{
			statement.getConnection().createStatement();
			resultSet = statement.executeQuery(query);
		}
		catch(Exception ex){
			ex.printStackTrace();
		}
		return resultSet;
	};
	
	//get the name of the columns from the database
	public static String[] getColumnNames(ResultSet resultSet){
		String[] columnNames = null;
		
		try{
			resultSetMetaData = resultSet.getMetaData();
			columnNames = new String[resultSetMetaData.getColumnCount()];
			int columnNumber = resultSetMetaData.getColumnCount();
			for(int i = 0; i < columnNumber; i++){
				columnNames[i] = resultSetMetaData.getColumnLabel(i + 1);
			}
		}
		catch (Exception e){
			e.printStackTrace();
		}
		return columnNames;
	};
	
	//get the table data 
	public static Object[][] getTableData(ResultSet resultSet){
		List<Object> data = new ArrayList<Object>();
		try{
			int columnNumber = resultSet.getMetaData().getColumnCount();
			
			while(resultSet.next()){
				Object[] tableData = new Object[columnNumber];
				for(int i = 0; i < tableData.length; i++){
					tableData[i] = resultSet.getObject(i + 1);
				}
				data.add(tableData);
			}
		}
		catch(Exception e){
			e.printStackTrace();
		}
		return data.toArray(new Object[0][0]);
	};
}


Was This Post Helpful? 0
  • +
  • -

#4 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8334
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Table query errors after adding new row

Posted 11 April 2012 - 07:21 PM

line 144: ResultSet resultSet = jdbc.setQuery(query);

Never heard of the setQuery() method surely not standard... most be particular to Postgress
The way I have always see that is

Statement statement = connection.createStatement();
ResultSet rs = statement.executeQuery("sql statement;");

And for your TableModel you may like that one:

http://www.dreaminco...snippet6437.htm

Happy coding
Was This Post Helpful? 0
  • +
  • -

#5 Silent Ace  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 42
  • Joined: 07-January 09

Re: Table query errors after adding new row

Posted 11 April 2012 - 07:33 PM

The setQuery is a method in JDBCConnection class and i do use the resultSet = statement.executeQuery(query)there. I only make a call to the displayTable method with a jdbc object from the class JDBCConnection.
Was This Post Helpful? 0
  • +
  • -

#6 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8334
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Table query errors after adding new row

Posted 11 April 2012 - 07:40 PM

Sorry, by bad, didn't realize JDVCConnection was your class

This statement does nothing :)

statement.getConnection().createStatement();

or actauly extractthe connecttion from the Statement an create a new Stement object out of it but without storing it no where

as you already have done
statement = connection.createStatement();

no need to repeat it or worts case

Statement otherStatement = statement.getConnection().createStatement();

or simply

resultSet = statement.executeQuery(query);

as your statement is already in your instance variable
Was This Post Helpful? 0
  • +
  • -

#7 Silent Ace  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 42
  • Joined: 07-January 09

Re: Table query errors after adding new row

Posted 11 April 2012 - 08:01 PM

You are correct that line does nothing and i did ignored the lines but i still have the same errors when i press the add button.
Was This Post Helpful? 0
  • +
  • -

#8 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8334
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Table query errors after adding new row

Posted 11 April 2012 - 08:10 PM

Add

public ResultSet setQuery(String query){
System.out.println("setQuery: " + query);

and see what it prints
Was This Post Helpful? 0
  • +
  • -

#9 Silent Ace  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 42
  • Joined: 07-January 09

Re: Table query errors after adding new row

Posted 11 April 2012 - 08:44 PM

It prints what i expeced to print first the select all table query and then the query from the addTableData() method which inserts values from the text fields to the database, but i get the errors and the data from the text fields is only visable after i restart the app. Sorry i don't really follow you, but thanks you for you help. This is still what i get when i press the add button.
SetQuery: SELECT * FROM phonebook
SetQuery: INSERT INTO phonebook VALUES ('great','djada','daskndkas','1515451')
org.postgresql.util.PSQLException: No results were returned by the query.
	at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:255)
	at app.JDBCConnection.setQuery(JDBCConnection.java:76)
	at app.TestClass.displayTable(TestClass.java:144)
	at app.TestClass.addTableData(TestClass.java:126)
	at app.TestClass$1.actionPerformed(TestClass.java:80)
	at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
	at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
	at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
	at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
	at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
	at java.awt.Component.processMouseEvent(Unknown Source)
	at javax.swing.JComponent.processMouseEvent(Unknown Source)
	at java.awt.Component.processEvent(Unknown Source)
	at java.awt.Container.processEvent(Unknown Source)
	at java.awt.Component.dispatchEventImpl(Unknown Source)
	at java.awt.Container.dispatchEventImpl(Unknown Source)
	at java.awt.Component.dispatchEvent(Unknown Source)
	at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
	at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
	at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
	at java.awt.Container.dispatchEventImpl(Unknown Source)
	at java.awt.window.dispatchEventImpl(Unknown Source)
	at java.awt.Component.dispatchEvent(Unknown Source)
	at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
	at java.awt.EventQueue.access$000(Unknown Source)
	at java.awt.EventQueue$3.run(Unknown Source)
	at java.awt.EventQueue$3.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
	at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
	at java.awt.EventQueue$4.run(Unknown Source)
	at java.awt.EventQueue$4.run(Unknown Source)
	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)
java.lang.NullPointerException
	at app.JDBCConnection.getTableData(JDBCConnection.java:107)
	at app.TestClass.displayTable(TestClass.java:147)
	at app.TestClass.addTableData(TestClass.java:126)
	at app.TestClass$1.actionPerformed(TestClass.java:80)
	at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
	at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
	at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
	at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
	at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
	at java.awt.Component.processMouseEvent(Unknown Source)
	at javax.swing.JComponent.processMouseEvent(Unknown Source)
	at java.awt.Component.processEvent(Unknown Source)
	at java.awt.Container.processEvent(Unknown Source)
	at java.awt.Component.dispatchEventImpl(Unknown Source)
	at java.awt.Container.dispatchEventImpl(Unknown Source)
	at java.awt.Component.dispatchEvent(Unknown Source)
	at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
	at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
	at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
	at java.awt.Container.dispatchEventImpl(Unknown Source)
	at java.awt.window.dispatchEventImpl(Unknown Source)
	at java.awt.Component.dispatchEvent(Unknown Source)
	at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
	at java.awt.EventQueue.access$000(Unknown Source)
	at java.awt.EventQueue$3.run(Unknown Source)
	at java.awt.EventQueue$3.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
	at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
	at java.awt.EventQueue$4.run(Unknown Source)
	at java.awt.EventQueue$4.run(Unknown Source)
	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)
java.lang.NullPointerException
	at app.JDBCConnection.getColumnNames(JDBCConnection.java:90)
	at app.TestClass.displayTable(TestClass.java:147)
	at app.TestClass.addTableData(TestClass.java:126)
	at app.TestClass$1.actionPerformed(TestClass.java:80)
	at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
	at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
	at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
	at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
	at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
	at java.awt.Component.processMouseEvent(Unknown Source)
	at javax.swing.JComponent.processMouseEvent(Unknown Source)
	at java.awt.Component.processEvent(Unknown Source)
	at java.awt.Container.processEvent(Unknown Source)
	at java.awt.Component.dispatchEventImpl(Unknown Source)
	at java.awt.Container.dispatchEventImpl(Unknown Source)
	at java.awt.Component.dispatchEvent(Unknown Source)
	at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
	at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
	at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
	at java.awt.Container.dispatchEventImpl(Unknown Source)
	at java.awt.window.dispatchEventImpl(Unknown Source)
	at java.awt.Component.dispatchEvent(Unknown Source)
	at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
	at java.awt.EventQueue.access$000(Unknown Source)
	at java.awt.EventQueue$3.run(Unknown Source)
	at java.awt.EventQueue$3.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
	at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
	at java.awt.EventQueue$4.run(Unknown Source)
	at java.awt.EventQueue$4.run(Unknown Source)
	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)


Was This Post Helpful? 0
  • +
  • -

#10 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8334
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Table query errors after adding new row

Posted 11 April 2012 - 08:59 PM

Quote

SetQuery: SELECT * FROM phonebook
SetQuery: INSERT INTO phonebook VALUES ('great','djada','daskndkas','1515451')


Wait a minute :)

SELECT * is a Statement.executeQuery() which returns a ResultSet
INSERT INTO is a Statement.excuteUpdate() which returns a int (number of rows affected)

both can't be performed by the same method
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1