craftleft.gif (3002 bytes)QuickTable
Home | API | Tutorial | Download | Support | Contact topblack.gif (108 bytes)


QuickTable User Cp  |  Register  |  Members  |  Search  |  Help
    |- QuickTable Discussion Forums > JDBC/Database Issues Post New Topic   Post A Reply
insert(vector,0) error (doing insert immediatly) printer friendly version
next newest post | next oldest post
Author Messages
infow
Unregistered
Edit or delete this message Reply w/Quote
Posted Wednesday, April 16, 2008 @ 06:27:43  

Hi,

when inserting a new vector in the table, qt immediatly do the "insert" with null value.
it's working when using insert(vector) instead of insert(vector,0)

to help you, here's the code with your example
Thanks and have a nice day
import javax.swing.*;

import quick.dbtable.*;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.sql.*;
import java.util.Vector;

public class QuickTableFrame extends JFrame {
quick.dbtable.DBTable dBTable1 = new quick.dbtable.DBTable();

public QuickTableFrame() {
// set Frame properties
setSize(500, 500);
setVisible(true);
JPanel jpan=new JPanel();
JButton bCommit=new JButton("Commit MySelf");
JButton bRefresh=new JButton("Refresh");
JButton bInsert=new JButton("insert");
// add to frame
getContentPane().setLayout(new BorderLayout());
getContentPane().add(dBTable1,BorderLayout.CENTER);
jpan.add(bCommit);
jpan.add(bRefresh);
jpan.add(bInsert);
getContentPane().add(jpan,BorderLayout.SOUTH);

// set the database driver to be used, we are using jdbc-odbc driver
dBTable1.setDatabaseDriver("sun.jdbc.odbc.JdbcOdbcDriver");
bInsert.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
Vector v = new Vector();
v.addElement("");
v.addElement("");
v.addElement("");
dBTable1.insert(v,0);
}
});
bRefresh.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
try
{
dBTable1.refresh();
}
catch (SQLException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});

bCommit.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae)
{
dBTable1.save();
try
{
dBTable1.getConnection().commit();
}
catch (SQLException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
/*
* set the jdbc url,"quicktabledemo" is the data source we have created
* for the database
*/
dBTable1.debug=true;
dBTable1.setJdbcUrl("jdbc:odbc:quicktabledemo");
dBTable1.postponeDBInsert = true;
dBTable1.autoCommit = false;

// set the select statement which should be used by the table
dBTable1.setSelectSql("SELECT Employee.Emp_Number, Employee.Emp_Name, " +
"Employee_status.Emp_Status " +
"FROM Employee , Employee_status " +
"WHERE Employee.Emp_Number = Employee_status.Emp_no");

//since 2 tables are involved in the above query , we need to add 2 update statements
dBTable1.addUpdateSql("update Employee set emp_name =? where emp_number =?", "2,1");
dBTable1.addUpdateSql("update Employee_status set emp_status=? where emp_no=?", "3,1");

//Add the insert statements
dBTable1.addInsertSql("insert into Employee (emp_number, emp_name) values (?,?)", "1,2");
dBTable1.addInsertSql("insert into employee_status (emp_no, emp_status) values (?, ?)", "1,3");

//Add delete statements
dBTable1.addDeleteSql("delete from Employee where emp_number = ?", "1");
dBTable1.addDeleteSql("delete from Employee_status where emp_no = ?", "1");
// to create the navigation bars for the table
dBTable1.createControlPanel();
dBTable1.getTable().setSurrendersFocusOnKeystroke(true);
dBTable1.enableTextOverwriteOnCellEdit = true;

try
{
//set database properties
dBTable1.connectDatabase();

//fetch the data from database to fill the table
dBTable1.refresh();
}
catch(SQLException e)
{
e.printStackTrace();
}
catch(ClassNotFoundException e)
{
e.printStackTrace();
}

//some jdbc drivers don't give the correct meta data for editable property of a column
dBTable1.getColumn(0).setReadOnly(false);
dBTable1.getColumn(1).setReadOnly(false);
dBTable1.getColumn(2).setReadOnly(false);
}

public static void main(String[] args) {
// create a new table frame
QuickTableFrame myframe = new QuickTableFrame();
}
}

Admin
Board Owner

Gender: Unspecified
Location:
Registered: Jul 2003
Status: Offline
Posts: 9

Click here to see the profile for Admin Send email to Admin Send private message to Admin Find more posts by Admin Edit or delete this message Reply w/Quote
Posted Sunday, April 20, 2008 @ 12:51:48  

use the insertSilent(Vector insertElements, int row) method instead.

insert method changes the row selection

infow
Unregistered
Edit or delete this message Reply w/Quote
Posted Wednesday, April 23, 2008 @ 03:27:23  

hi,
thanks for your help but it's the same mistake.

Your QT is inserting a new line without error BUT when i click on the first value to enter data, i have the error (QT is inserting in DB)

Please try my code and you will see

Have a nice day

Admin
Board Owner

Gender: Unspecified
Location:
Registered: Jul 2003
Status: Offline
Posts: 9

Click here to see the profile for Admin Send email to Admin Send private message to Admin Find more posts by Admin Edit or delete this message Reply w/Quote
Posted Sunday, April 27, 2008 @ 09:27:20  

I tried your sample code. It works perfectly.

My steps, run your sample and just press the insert button and when I try to type into the new row which is added, it is not trying to update database.

infow
Unregistered
Edit or delete this message Reply w/Quote
Posted Monday, April 28, 2008 @ 03:19:29  

hi,
thanks for your reply
with the function insertsilence, there's no error message when you press "Insert"
BUT the error message is coming when you click with mouse into the first colum that has been inserted !
Your QT make a "insert" when i enter the first column ! ! !

--------------
xecuting sql insert into Employee (emp_number, emp_name) values (?,?) with arguments:
Argument 1: Datatype in database:INTEGER. Value:NULL
Argument 2: Datatype in database:VARCHAR. Value:NULL
java.sql.SQLException: [Microsoft][Pilote ODBC Microsoft Access] Un index ou une clé principale ne peut pas contenir une valeur Null.
at sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown Source)
at sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source)
at sun.jdbc.odbc.JdbcOdbc.SQLExecute(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcPreparedStatement.execute(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcPreparedStatement.executeUpdate(Unknown Source)
at quick.dbtable.DBTableModel.insert(DBTableModel.java:2403)
at quick.dbtable.DBTableModel.rowSelectionChanged(DBTableModel.java:2172)
at quick.dbtable.DBTable$2.valueChanged(DBTable.java:519)
-----------------------
please try

Have a nice day

Admin
Board Owner

Gender: Unspecified
Location:
Registered: Jul 2003
Status: Offline
Posts: 9

Click here to see the profile for Admin Send email to Admin Send private message to Admin Find more posts by Admin Edit or delete this message Reply w/Quote
Posted Monday, April 28, 2008 @ 17:45:15  

I used your code as it is. I used the insert method, not the insertsilent method. I followed the same steps as yours. It did not execute the insert sql when I clicked on the first cell in the inserted row.

can you give your JDK and quicktable version?

infow
Unregistered
Edit or delete this message Reply w/Quote
Posted Tuesday, April 29, 2008 @ 02:03:12  

java 1.6.0_03
qt: 2.0.5.28
using eclipse 3.3.1.1

please dont use your button "insert" but mine (under right after "refresh" button)

i don't know but it's not working !
I think you click the false button, no ?

thank for help and have a nice day

infow
Unregistered
Edit or delete this message Reply w/Quote
Posted Wednesday, May 7, 2008 @ 10:00:41  

hi,
i have no answer .
Can you reproduce the problem when you use "my" button ?

thank and have a nice day

Admin
Board Owner

Gender: Unspecified
Location:
Registered: Jul 2003
Status: Offline
Posts: 9

Click here to see the profile for Admin Send email to Admin Send private message to Admin Find more posts by Admin Edit or delete this message Reply w/Quote
Posted Thursday, May 8, 2008 @ 21:45:35  

I used your button only and it worked.

I need some more time to test in the configuration which you gave.

Admin
Board Owner

Gender: Unspecified
Location:
Registered: Jul 2003
Status: Offline
Posts: 9

Click here to see the profile for Admin Send email to Admin Send private message to Admin Find more posts by Admin Edit or delete this message Reply w/Quote
Posted Sunday, May 11, 2008 @ 13:11:13  

I was able to reproduce this in JDK 1.6 and teh issue is resolved. Please download the latest version.
infow
Unregistered
Edit or delete this message Reply w/Quote
Posted Monday, May 12, 2008 @ 11:24:41  

Hi,
thanks for your help but the lastest version is still 2.0.5.28.
i just download the latest SOURCE file and it's the same version.
The problem is not resolved (always same error)

please update your site/file.

Thank for your help and have a nice day

infow
Unregistered
Edit or delete this message Reply w/Quote
Posted Monday, June 9, 2008 @ 10:35:10  

Hi,
any news after a few weeks ?

the file is still in version 2.0.5.28

you have said you have uploaded the file and i don't see that ...

Thank and have a nice day

Post New Topic   Post A Reply Jump to:
Contact Us | QuickTable - A Java DBGrid | Privacy Policy All times are GMT -5 Hours.
Welcome to QuickTable Forums, Guest!  
Login
Username :
Password :
In order to fully utilize the abilities of this board, you are required to register as a member. Registration is free, and allows you to do lots of things including turning on or off certain features of this board. Register now!
Powered by CuteCast v2.0 BETA 2
Copyright © 2001-2003 ArtsCore Studios