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 > General QuickTable Support/Help Post New Topic   Post A Reply
Updating fields printer friendly version
next newest post | next oldest post
Author Messages
Tom Gubler
Unregistered
Edit or delete this message Reply w/Quote
Posted Thursday, June 3, 2004 @ 20:38:03  

I have converted an MSAccess database to MySQL and wish to use QuickTable to edit the Tables. I get a list of tables in the database from mySql and create a tree and then by clicking on on the node create a quicktable which I may wish to edit, add, delete etc. I send SELECT * FROM tablename. So I run through the columns to create the appropriate strings to send to addUpdateSql() as I don't know beforehand what changes might be required and I end up with something like:

UPDATE accounts SET Account_No=?, Company_Name=?, Company_Address=?, City=?, State=?, Postcode=?, Phone_Number=?, Fax_Number=?, Contact_Name=?, Pricing_Structure=?, Tax_Exemption=?, Credit_OK=?,1,2,3,4,5,6,7,8,9,10,11,12

but when I edit a field quicktable wants to change every column in every row in the table and will if there are no unique indexes to prevent it. Is it possible to do what I want to do which is just update the one field in the one row and if so what else is required?

public class QuickTableFrame extends JFrame
{
public QuickTableFrame(String sql, String tableName) {
//set Frame properties
pack();
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
setBounds(0, 0, screenSize.width, screenSize.height - 32);
setVisible(true);

//create a new quicktable
// quick.dbtable.DBTable dBTable1 = new quick.dbtable.DBTable();
DBTable dBTable1 = new DBTable();

//add to frame
getContentPane().add(dBTable1);

//set the database driver to be used, we are using jdbc-odbc driver com.mysql.jdbc.Driver
// dBTable1.setDatabaseDriver("sun.jdbc.odbc.JdbcOdbcDriver");
dBTable1.setDatabaseDriver("com.mysql.jdbc.Driver");
dBTable1.setJdbcUrl(
"jdbc:mysql://xxxxx:3306/xxx?user=xxxx&password=xxxxxxx");

dBTable1.setSelectSql(sql); // for example: SELECT * FROM ACCOUNTS
dBTable1.setRowCountSql("SELECT count(*) from "+tableName);
dBTable1.debug = true;
dBTable1.createControlPanel();

try {
//connect to database & create a connection
dBTable1.connectDatabase();

//fetch the data from database to fill the table
dBTable1.refresh();
String uString = "";
String pString = "UPDATE " + tableName + " SET ";
if (tableName.length() != 0) {
// it's a table so work out field names

int numColumns = dBTable1.getColumnCount();
for (int n = 0; n < numColumns; n++) {
pString += dBTable1.getColumn(n).getColumnName() + "=?";
if (n != numColumns - 1)
pString += ", ";
}
for (int n = 1; n <= numColumns; n++) {
uString += n;
if (n != numColumns) uString += ",";
}
}
dBTable1.addUpdateSql(pString, uString);
}
catch (SQLException e) {
e.printStackTrace();
}
catch (ClassNotFoundException e) {
e.printStackTrace();
}

}

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, June 3, 2004 @ 20:51:18  

There is a problem with the update query, you are missing the "where" clause in your update query

Your query

"UPDATE accounts SET Account_No=?, Company_Name=?, Company_Address=?, City=?, State=?, Postcode=?, Phone_Number=?, Fax_Number=?, Contact_Name=?, Pricing_Structure=?, Tax_Exemption=?, Credit_OK=?" ,"1,2,3,4,5,6,7,8,9,10,11,12"

The correct query

UPDATE accounts SET Company_Name=?, Company_Address=?, City=?, State=?, Postcode=?, Phone_Number=?, Fax_Number=?, Contact_Name=?, Pricing_Structure=?, Tax_Exemption=?, Credit_OK=? where Account_No=?" ,"2,3,4,5,6,7,8,9,10,11,12,1"

You don't need to set dBTable1.setRowCountSql() for simple queries like select * from accounts, it will be automatically computed

The other suggestion is,when you repeatedly show data from differnet tables, when users click on tree node, its enough if you create the DBTable instance once, connect to DB once and then change selectsql, updatesql, deletesql and call refresh() for each node. Make sure you call clearAllSettings() before you change the sqls for the new table.

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