Newbie:how to create a page with 4 textfields and send data to MySql DB

Dear all,

i have created a page called page1 with 1 submit button named 'submitButton' and 4 textfields named:

'date'

'item'

'contact'

'phone'

I have created a MySql DB table with the schema named 'association' and table named todolist3. Fields created in the table are :

'Date' - >INTEGER->Primary

'Item' ->VARCHAR(100)

'Contact'->VARCHAR(45)

'Phone_contact'->INTEGER

what i want to do is to send the data from the 4 textfields to the database when i click the submit button. Below is the code i out in submit button. please kindly help as i have tested different ways but none of them works. thank you!!!

public String submitButton_action() {

try {

if ( todolist3DataProvider.canAppendRow() )

{

String item1=(String)item.getText();

String contact1=(String)contact.getText();

Integer phone1=(Integer)phone.getText();

Integer date1=(Integer)date.getText();

RowKey rowKey = todolist3DataProvider.appendRow();

todolist3DataProvider.setCursorRow(rowKey);

todolist3DataProvider.setValue("todolist3.Date", date1);

todolist3DataProvider.setValue("todolist3.Item",item1);

todolist3DataProvider.setValue("todolist3.Contact",contact1);

todolist3DataProvider.setValue("todolist3.Phone_contact",phone1);

} else {

error("submitButton_action() -- cannot append todolist3 record");

}

} catch (Exception e) {

error("Page1::submitButton_action-- something's wrong trying to append todolist3 record");

}

return null;

}

}

[1664 byte] By [jaybuffer88a] at [2007-11-27 6:24:29]
# 1
Hi There,Take a look at following tutorials http://developers.sun.com/jscreator/learning/tutorials/2/inserts_updates_delete s.html#02 http://developers.sun.com/jscreator/learning/tutorials/2/databoundcomponents.ht mlThanksK
kish@suna at 2007-7-12 17:43:22 > top of Java-index,Development Tools,Java Tools...
# 2

I have refered to many tutorials and none of them really work for my example, i did not get any error but just that no data send to the Db i created.

Pls help, i have been trying this for quite some time, i just need a program with a textfield, a button that allows user to input a data and send it to the database and and a label to retrieve the data and display to the page.

Pls help, i almost give up!!!

jaybuffer88a at 2007-7-12 17:43:22 > top of Java-index,Development Tools,Java Tools...
# 3

Hi,

I think that you have forgotten to commit changes. Modify your code to look like this:

// ....

RowKey rowKey = todolist3DataProvider.appendRow();

todolist3DataProvider.setCursorRow(rowKey);

todolist3DataProvider.setValue("todolist3.Date", date1);

todolist3DataProvider.setValue("todolist3.Item",item1);

todolist3DataProvider.setValue("todolist3.Contact",contact1);

todolist3DataProvider.setValue("todolist3.Phone_contact",phone1);

// commit your changes !!!

todolist3DataProvider.commitChanges();

} else {

// ....

best regards

Grzegorz

Grzegorz.Kluczeka at 2007-7-12 17:43:22 > top of Java-index,Development Tools,Java Tools...
# 4
It doesnt work even i have added the followinf line:todolist3DataProvider.commitChanges();there isn't any error juz that the data is not sent to the DB, Pls help!!thanks!
jaybuffer88a at 2007-7-12 17:43:22 > top of Java-index,Development Tools,Java Tools...
# 5

Are you saying that it the row does not get added to your database and no errors are emitted to explain why it is not adding the row? What methods are you using to verify there is no runtime / programming error?

Do you have a message group component on the page? Are you looking at the server log to see if there are any messages? Do you have a call to log("put some message here") in the catch clause to print out exceptions?

When you call canAppendRow() i on your data provider is it returning true?

What about looking at the database log. See http://blogs.sun.com/jfbrown/

jetsonsa at 2007-7-12 17:43:22 > top of Java-index,Development Tools,Java Tools...