1

我创建了一个名为 Department_Table 的“Jtable”,现在使用 SQL 查询我试图将我的数据库表内容填充到我的 Jtable 中。

我已成功完成,但我的数据库表中的时间戳列未正确显示。你能帮我找出这个程序有什么问题吗?

代码:

public void  UpdateTable()
    {        
        try
        {
            Connection conn=Address.getOracleConnection();

            String sql="Select * from department";
            /*
             Using to_char my statement looks like this and it works

            String sql="Select department_id,name,to_char(created_on,'dd/MM/yyyy HH24:MI:SS') from department";   
            */

            PreparedStatement pst=conn.prepareStatement(sql);
            ResultSet res=pst.executeQuery();
            Department_Tabel.setModel(DbUtils.resultSetToTableModel(res));
        }
        catch(Exception e)
        {
             Notify.showMessageDialog(null,""+e+"","Error Generating Table",Notify.ERROR_MESSAGE);
        }
    }

输出:

departmentid    name                         createdon

1            name1           oracle.sql.TIMESTAMP@19eda2c

2            name2              oracle.sql.TIMESTAMP@59a34
4

1 回答 1

0

此链接应该可以帮助您理解映射并进行格式化以正确显示内容。

http://docs.oracle.com/javase/1.5.0/docs/guide/jdbc/getstart/mapping.html

于 2012-12-27T07:29:06.483 回答