M
Maenne
Hi together,
I'm working with eclipse 3.4.1, java 2 jdk 1.4.2.01 and jigloo for GUI.
Maybe someone can help me.
First I'd build a GUI with jigloo. (With a JTABLE). Then I created a
JDBC-ODBC connection to a MSAccess database. So far, so good.
Now my problem:
I have no idea, how to connect the JTABLE with the data from the
database.
I know, how to create the first column, but how to place the WHILE-statement,
so that i get all the data?
Here is my sourcecode:
private JTable getAccesstab() throws SQLException {
if(Accesstab == null) {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbcdbcRIVER={Microsoft Access Driver (*.mdb)};DBQ=d:/Testdaten.mdb");
Statement stmt2 = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
ResultSet tbladressen = stmt2.executeQuery("SELECT * FROM [Adressen];");
ResultSetMetaData rsmd = tbladressen.getMetaData();
int clmCnt = rsmd.getColumnCount();
String[][] items1 = new String[clmCnt],new String[] { "Vorname", "Nachname" };
tbladressen.first();
while (tbladressen.next()) {
for (int i = 1; i <= clmCnt; i++) {
items1=tbladressen.getString(i);
}
tbladressen.next();
}
TableModel AccesstabModel =
new DefaultTableModel(
new String[][] { items1 },
new String[] { "Vorname", "Nachname" });
// new String[][] { { tbladressen.getString(3), tbladressen.getString(4) },
// { "Three", "Four" },
// { "Three", "Four" } },
// new String[] { "Vorname", "Nachname" });
Accesstab = new JTable();
GroupLayout AccesstabLayout = new GroupLayout((JComponent)Accesstab);
Accesstab.setLayout(AccesstabLayout);
AccesstabLayout.setHorizontalGroup(AccesstabLayout.createParallelGroup());
AccesstabLayout.setVerticalGroup(AccesstabLayout.createParallelGroup());
Accesstab.setModel(AccesstabModel);
tbladressen.close();
con.close();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return Accesstab;
}
thanks for your help
Maenne
I'm working with eclipse 3.4.1, java 2 jdk 1.4.2.01 and jigloo for GUI.
Maybe someone can help me.
First I'd build a GUI with jigloo. (With a JTABLE). Then I created a
JDBC-ODBC connection to a MSAccess database. So far, so good.
Now my problem:
I have no idea, how to connect the JTABLE with the data from the
database.
I know, how to create the first column, but how to place the WHILE-statement,
so that i get all the data?
Here is my sourcecode:
private JTable getAccesstab() throws SQLException {
if(Accesstab == null) {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbcdbcRIVER={Microsoft Access Driver (*.mdb)};DBQ=d:/Testdaten.mdb");
Statement stmt2 = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
ResultSet tbladressen = stmt2.executeQuery("SELECT * FROM [Adressen];");
ResultSetMetaData rsmd = tbladressen.getMetaData();
int clmCnt = rsmd.getColumnCount();
String[][] items1 = new String[clmCnt],new String[] { "Vorname", "Nachname" };
tbladressen.first();
while (tbladressen.next()) {
for (int i = 1; i <= clmCnt; i++) {
items1=tbladressen.getString(i);
}
tbladressen.next();
}
TableModel AccesstabModel =
new DefaultTableModel(
new String[][] { items1 },
new String[] { "Vorname", "Nachname" });
// new String[][] { { tbladressen.getString(3), tbladressen.getString(4) },
// { "Three", "Four" },
// { "Three", "Four" } },
// new String[] { "Vorname", "Nachname" });
Accesstab = new JTable();
GroupLayout AccesstabLayout = new GroupLayout((JComponent)Accesstab);
Accesstab.setLayout(AccesstabLayout);
AccesstabLayout.setHorizontalGroup(AccesstabLayout.createParallelGroup());
AccesstabLayout.setVerticalGroup(AccesstabLayout.createParallelGroup());
Accesstab.setModel(AccesstabModel);
tbladressen.close();
con.close();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return Accesstab;
}
thanks for your help
Maenne