-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4027111
By: lolitta_lee
Hi,
I would like to retrieve from database to listbox through ODBC. After I run the following code, I got an error "java.lang.IllegalArgumentException: array element type mismatch ".
How can I get an array data?
<window xmlns:h="http://www.w3.org/1999/xhtml" > <zscript>
import java.sql.*;
submit1() {
String url = "jdbc:mysql://localhost/testDB";
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection(url,"dbUser", "password");
Statement StatementRecordset = con.createStatement();
String SQL = "SELECT * from product order by PID desc";
ResultSet rs = StatementRecordset.executeQuery(SQL);
String[] rDetail = new String[10];
for (int i=0; i < 10; i++){
rDetail[i] = rs.getString("productName");
}
return rDetail;
}
submit2(){
String[] tem = new String[10];
tem = submit1();
strset = new SimpleListModel(tem);
list.model=strset;
}
</zscript>
<zscript>
String[] data = new String[15];
for(int j=0; j < data.length; ++j) {
data[j] = "option "+j;
}
ListModel strset = new SimpleListModel(data);
</zscript>
<listbox id="list" width="200px" rows="10" model="${strset}">
<listhead>
<listheader label="Load on demend"/>
</listhead>
</listbox>
<button label=" Check " onClick="submit2()"/> </window>
Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4027271
By: henrichen
Please post stack traces.
/henri
Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4028024
By: lolitta_lee
Hi,
After I run the zscript, just got the alert message
"java.lang.IllegalArgumentException: array element type mismatch " only.
I just added an exception into the program and run that
submit2(){
try{
String[] tem = new String[10];
tem = submit1();
strset = new SimpleListModel(tem);
list.model=strset;
}
catch (Exception e){
System.out.println(e);
}
}
Here is the result from tomcat's stdout log =>
log4j:WARN No appenders could be found for logger (org.apache.commons.digester.Digester.sax).
log4j:WARN Please initialize the log4j system properly.
java.lang.ArrayStoreException: java.lang.IllegalArgumentException: array element type mismatch
My table structure and sample data:
CREATE TABLE `product` (
`PID` bigint(20) NOT NULL auto_increment, `ProductName` varchar(50) NOT NULL, PRIMARY KEY (`PID`)
)
Sample Data:
1, Test-Stock A01
2, Test-Stock B72
3, Test-Stock A22
4, Test-Stock Z01
5, Test-Stock Z02
6, Test-Stock Z03
7, Test-Stock A25
8, Test-Stock B66
9, Test-Stock B68
10, Test-Stock A28
I have no any idea in "array element type mismatch", it seem the data have no problem.
Thanks and regards,
Lolitta
Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4028051
By: tomyeh
Post it to the Help forum. Thanks.
Can we use postgreSQL database in ZKforum??????????????? If we do than how to use is plz tell me in detail..............
Have you look here.
Download the demo todo application zip file unpack it and go through the codes. You can see how to connect and work with direct JDBC calls.
--> todo.war\src\org\zkforge\todo\event\EventDAO.java
best
Stephan
PS: An other approach is to use an Object Relational Mapper (ORM) that maps table records to java objects. Many guys work in this way. Have a look here.
Asked: 2006-11-23 09:55:27 +0800
Seen: 736 times
Last updated: May 03 '11