怎样将oracle数据库中某个表的数据读取出来,然后在java的JTable中显示出来
这里的代码哪里错了?怎么在JTable显示不出来?staticvoidquery(){DefaultTableModeldt=newDefaultTableModel()...
这里的代码哪里错了?怎么在JTable显示不出来?
static void query()
{
DefaultTableModel dt=new DefaultTableModel();
JTable jtable=showframe.jtable;
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
ct=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:ORCL","scott","cecilia");
ps=ct.prepareStatement("select * from employee where 员工号=1");
ResultSetMetaData rsmd = rs.getMetaData();
int numberOfColumns=rsmd.getColumnCount();
//以下是显示数据库中的列名的代码
int b=1;
while(b<=numberOfColumns)
{
dt.addColumn(rsmd.getColumnName(b));
b++;
}
//以下是在表格中显示数据中的内容
while(rs.next())
{
Vector newRow=new Vector();
int c=1;
while(c<=numberOfColumns)
{
newRow.addElement(rs.getString(c));
c++;
}
dt.addRow(newRow);
}
jtable.setModel(dt);
}
catch(Exception ex){};
} 展开
static void query()
{
DefaultTableModel dt=new DefaultTableModel();
JTable jtable=showframe.jtable;
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
ct=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:ORCL","scott","cecilia");
ps=ct.prepareStatement("select * from employee where 员工号=1");
ResultSetMetaData rsmd = rs.getMetaData();
int numberOfColumns=rsmd.getColumnCount();
//以下是显示数据库中的列名的代码
int b=1;
while(b<=numberOfColumns)
{
dt.addColumn(rsmd.getColumnName(b));
b++;
}
//以下是在表格中显示数据中的内容
while(rs.next())
{
Vector newRow=new Vector();
int c=1;
while(c<=numberOfColumns)
{
newRow.addElement(rs.getString(c));
c++;
}
dt.addRow(newRow);
}
jtable.setModel(dt);
}
catch(Exception ex){};
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询