int id = 0;
int age = 0;
Connection conn = null;
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection(
"jdbc:oracle:thin:@localhost:1521:orcl", "scott", "123");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
ResultSet res = null;
CallableStatement cstm = null;
try {
cstm = conn.prepareCall("{call tu_queryAlls(?)}");
cstm.registerOutParameter(1, oracle.jdbc.OracleTypes.CURSOR);
cstm.execute();
res = (ResultSet) cstm.getObject(1);
int count = 0;
while (res.next())
{
count++;
}
cstm.execute();
res = (ResultSet) cstm.getObject(1);
Object[][] info = new Object[count][3];
count = 0;
while (res.next()) {
info[count][0] = Integer.valueOf(res.getInt(1));
info[count][1] = res.getString(2);
info[count][2] = Integer.valueOf(res.getInt(3));
count++;
}
String[] columnNames = { "编号", "姓名", "年龄" };
DefaultTableModel dModel = new DefaultTableModel(info, columnNames);
jTable1.setModel(dModel);
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
} finally {
try {
cstm.close();
conn.close();
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
int age = 0;
Connection conn = null;
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection(
"jdbc:oracle:thin:@localhost:1521:orcl", "scott", "123");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
ResultSet res = null;
CallableStatement cstm = null;
try {
cstm = conn.prepareCall("{call tu_queryAlls(?)}");
cstm.registerOutParameter(1, oracle.jdbc.OracleTypes.CURSOR);
cstm.execute();
res = (ResultSet) cstm.getObject(1);
int count = 0;
while (res.next())
{
count++;
}
cstm.execute();
res = (ResultSet) cstm.getObject(1);
Object[][] info = new Object[count][3];
count = 0;
while (res.next()) {
info[count][0] = Integer.valueOf(res.getInt(1));
info[count][1] = res.getString(2);
info[count][2] = Integer.valueOf(res.getInt(3));
count++;
}
String[] columnNames = { "编号", "姓名", "年龄" };
DefaultTableModel dModel = new DefaultTableModel(info, columnNames);
jTable1.setModel(dModel);
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
} finally {
try {
cstm.close();
conn.close();
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}