0

Problem with insert data to mysql database

asked 2006-02-10 03:47:34 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=3568631

By: nobody

I have problem with insert data to mysql database. i used zscript for embed
java.sql.*
code is below

<window title="JDBC demo" border="normal">
<zscript>{
import java.sql.*;
void submit() {


Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://localhost:3306/javatest";
Connection con = DriverManager.getConnection(url,"root", "root");
PreparedStatement stmt = con.prepareStatement("INSERT INTO testdata values(?,?,?)");

stmt.set(1, null);
stmt.set(2, name.value);
stmt.set(3, number.value);

stmt.executeUpdate();


con.close();

}
}</zscript>
<grid>
<rows>
<row>Name : <textbox id="name"/></row>
<row>Number: <textbox id="number"/></row>
<row><button label="submit" onClick="submit()"/></row>
</rows>
</grid>
</window>


i don't understand the error, however if i delete stmt.set(1, null);
stmt.set(2, name.value);
stmt.set(3, number.value);
and put value inside the qurie, it will works. can any one help me please.
i spent hours to do this, still not working.

delete flag offensive retag edit

7 Replies

Sort by ยป oldest newest

answered 2006-02-10 04:02:37 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=3568639

By: tomyeh

The order is wrong. ZK interpret ZUML from top to bottom. Thus, when zscript is evaluated, your textboxes are not created yet.

link publish delete flag offensive edit

answered 2006-02-10 04:04:40 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=3568644

By: tomyeh

Sorry, I didn't see you declared it as a function (submit()). It is not the issue I mentioned.

Would you post the error message?

link publish delete flag offensive edit

answered 2006-02-10 04:34:30 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=3568663

By: nobody

This is the whole error message.

---------------------------------------------
Sourced file: inline evaluation of : "submit();" : Error in method invocation:
Method set(int,null) not found in calss'com.mysql.jdbc.ServerPreparedStatement'
: at Line 12 ; in file; inline evaluation of :"{ import java.sql.*;
void submit() { Class.forName("com.mysql.jdbc..." : stmt.set(1,
null) Called from method: submit: at line:1 : in file: inline evalutaion of
: "submit();" :submit()
------------------------------------------------
i think is the method name.value and number.value is not working rihgt, also i am not sure about the first value null.

link publish delete flag offensive edit

answered 2006-02-10 04:43:36 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=3568671

By: tomyeh

It is caused by stmt.set(1, null) (as indicated by the error message).

Reason: BeanShell has no idea to apply which method due to null.

Solution: stm.setObject, or stmt.set(1, (Object)null), or stmt.set(1, (String)null)... depending on your need.

link publish delete flag offensive edit

answered 2006-02-10 04:44:47 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=3568673

By: tomyeh

BTW, this kind of problem is easier to detect if you write them into a Java file and Java compiler would tell you more detailed info.

link publish delete flag offensive edit

answered 2006-02-10 04:52:38 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=3568677

By: henrichen

The key information in the log is:

Error in method invocation:
Method set(int,null) not found in calss'com.mysql.jdbc.ServerPreparedStatement'

I don't remember there is a set() methods in Jdbc PreparedStatement. Is that a dialect of MySQL? Maybe you want to try the setObject() or setXxx() based on the value's type.

/henri

link publish delete flag offensive edit

answered 2006-02-10 14:09:12 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=3569289

By: nobody

thanks all you help, i found out the problem it is the set***() problem

stmt.setNull(1, 1);
stmt.setObject(2, name.value);
stmt.setObject(3, number.value);

this works.

Thanks again!

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2006-02-10 03:47:34 +0800

Seen: 686 times

Last updated: Feb 10 '06

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More