Plugins (1083)


Training and Consulting (44)



EPIC Poll

What is your favourite developer portal?

[ Results | Polls ]

Votes: 540
Comments: 0

Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
lisa
9 Post subject: show sql data in my tree  PostPosted: May 05, 2008 - 10:16 AM



Joined: May 04, 2008
Posts: 2

I make a java application as a test,but sth error happened!
here is my program:
public class TreeSample {
public static void main(String[] args) throws SQLException {
final Display display = Display.getDefault();
final Shell shell = new Shell();
shell.setSize(210, 160);
shell.setText("Tree示例");
shell.setLayout(new FillLayout());
createContents(shell);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}

private static void createContents(Shell shell) throws SQLException {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}

Tree tree = new Tree(shell, SWT.NONE);
tree.setHeaderVisible(true);
tree.setLinesVisible(true);
tree.setRedraw(false);

Connection con = DriverManager.getConnection("jdbc:odbc:LISA", "", "");
Statement sql = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
ResultSet rs = sql.executeQuery("select distinct productname from partinfo");
rs.last();
int intRowCount=rs.getRow();

String[] product = new String[intRowCount];
String[][] part=null;
int i = 0;
rs.first();
while (rs.next()) {
product[i]= rs.getString("productname");
i++;

}
for (int j = 0; j < product.length - 1; j++) {
ResultSet rs1 = sql.executeQuery("select partname from partinfo where productname='"+ product[j] + "'");
int k = 0;
rs1.last();
int intRowCount1=rs1.getRow();
part = new String[intRowCount][intRowCount1] ;
rs1.first();
while (rs1.next()) {
part[j][k] = rs1.getString("partname");
k++;
}
}
for ( i = 0; i < product.length; i++) {
TreeItem parent = new TreeItem(tree, SWT.NONE);
parent.setText(product[i]);
for (int j = 0; j < part[i].length; j++) {
TreeItem child = new TreeItem(parent, SWT.NONE);
child.setText(part[i][j]);
}
}
tree.setRedraw(true);
}
}

the result is:
Exception in thread "main" java.lang.IllegalArgumentException: Argument cannot be null
at org.eclipse.swt.SWT.error(SWT.java:3358)
at org.eclipse.swt.SWT.error(SWT.java:3297)
at org.eclipse.swt.SWT.error(SWT.java:3268)
at org.eclipse.swt.widgets.Widget.error(Widget.java:435)
at org.eclipse.swt.widgets.TreeItem.setText(TreeItem.java:1542)
at org.eclipse.swt.widgets.TreeItem.setText(TreeItem.java:1577)
at TreeSample.createContents(TreeSample.java:73)
at TreeSample.main(TreeSample.java:23)

I want everyone's help, thanks a lot and best regards![/b]
 
 View user's profile Send private message  
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT - 6 Hours
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2004 The PNphpBB Group
Credits