0

Retrieve data fm DB to Listboxthrough ODBC

asked 2006-11-23 09:55:27 +0800

admin gravatar image admin
18691 1 10 129
ZK Team


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>


delete flag offensive retag edit

6 Replies

Sort by ยป oldest newest

answered 2006-11-23 12:45:33 +0800

admin gravatar image admin
18691 1 10 129
ZK Team


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

By: henrichen

Please post stack traces.

/henri

link publish delete flag offensive edit

answered 2006-11-24 02:41:25 +0800

admin gravatar image admin
18691 1 10 129
ZK Team


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

link publish delete flag offensive edit

answered 2006-11-24 03:13:19 +0800

admin gravatar image admin
18691 1 10 129
ZK Team


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

By: tomyeh

Post it to the Help forum. Thanks.

link publish delete flag offensive edit

answered 2011-05-02 06:59:38 +0800

samit1010 gravatar image samit1010
15

i would like to retrieve data from postgre database and show data in grid in row and column format what should i do?How to write the code for this.?plz reply me...........


From Samir

link publish delete flag offensive edit

answered 2011-05-03 00:30:35 +0800

samit1010 gravatar image samit1010
15

updated 2011-05-03 00:31:06 +0800

Can we use postgreSQL database in ZKforum??????????????? If we do than how to use is plz tell me in detail..............

link publish delete flag offensive edit

answered 2011-05-03 04:31:33 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

updated 2011-05-03 04:50:36 +0800

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.

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-11-23 09:55:27 +0800

Seen: 735 times

Last updated: May 03 '11

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