-
FEATURED COMPONENTS
First time here? Check out the FAQ!
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.
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.
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?
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.
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.
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.
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
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!
Asked: 2006-02-10 03:47:34 +0800
Seen: 686 times
Last updated: Feb 10 '06