| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 512 人关注过本帖
标题:集合到入到表
取消只看楼主 加入收藏
天一
Rank: 1
等 级:新手上路
帖 子:94
专家分:0
注 册:2005-8-1
收藏
 问题点数:0 回复次数:0 
集合到入到表

//怎么没有结果输出谁能帮我处理以下 package queryintable;

import java.awt.*; import java.awt.event.*; import java.sql.*; import java.util.*; import javax.swing.*; import javax.swing.event.*;

import javax.swing.table.*; public class QueryInTableFrame extends JFrame { public static void main(String args[]) { QueryInTableFrame frm=new QueryInTableFrame(); } public JPanel contentPane;

public JButton queryintableButton=new JButton(); Vector vector; String title[]={"编号","姓","名","电话","住址","城市","国家","婚姻"}; Connection connection=null; Statement statement=null; ResultSet rs=null; AbstractTableModel tm; public QueryInTableFrame() { // this.getContentPane().add(contentPane); Container cond=getContentPane(); cond.add(contentPane); setSize(452,345); this.setTitle("利用表格输出结果"); setVisible(true); enableEvents(AWTEvent.WINDOW_EVENT_MASK); try { jbInit(); } catch(Exception e) { System.out.println(e.toString()); } } private void jbInit()throws Exception { contentPane=new JPanel(); queryintableButton.setLabel("表格输出查询结果"); queryintableButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { queryintableButton_actionPerformed(e); } });

contentPane.add(queryintableButton,BorderLayout.SOUTH); createtable(); } protected void procesWindowEvent(WindowEvent e) { super.processWindowEvent(e); if(e.getID()==WindowEvent.WINDOW_CLOSING) { System.exit(0); } } void createtable() { JTable table; JScrollPane scroll; vector=new Vector(); tm=new AbstractTableModel() { public int getColumnCount() { return title.length; } public int getRowCount() { return vector.size(); } public Object getValueAt(int row,int column) { if(!vector.isEmpty()) { return((Vector)vector.elementAt(row)).elementAt(column); } else { return null; } } public void setValueAt(Object value,int row,int column) { } public String getColumnName(int column) { return title[column]; } public Class getColumnClass(int c) { return getValueAt(0,c).getClass(); } public boolean isCellEditable(int row,int column) { return false; } };

table=new JTable(tm); table.setToolTipText("Display quety result"); table.setAutoResizeMode(table.AUTO_RESIZE_OFF); table.setCellSelectionEnabled(false); table.setShowHorizontalLines(true); table.setShowVerticalLines(true);

} void queryintableButton_actionPerformed(ActionEvent e) { try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); String url="jdbc:odbc:Hello"; connection=DriverManager.getConnection(url); statement=connection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE); String sql="select * from authors"; rs=statement.executeQuery(sql); vector.removeAllElements(); tm.fireTableStructureChanged(); while(rs.next()) { Vector rec_vector=new Vector(); rec_vector.addElement(String.valueOf(rs.getInt("au_id"))); rec_vector.addElement(rs.getString("au_lname")); rec_vector.addElement(rs.getString("au_fname")); rec_vector.addElement(String.valueOf(rs.getInt("phone"))); rec_vector.addElement(rs.getString("address")); rec_vector.addElement(rs.getString("city")); rec_vector.addElement(rs.getString("state")); rec_vector.addElement(String.valueOf(rs.getInt("contract"))); } tm.fireTableStructureChanged(); rs.close(); } catch(SQLException es) { System.out.println("\nERROR:-------SQLException-------\n"); while(es!=null) { System.out.println("Message:"+es.getMessage().toString()); System.out.println("SQLState:"+es.getSQLState().toString()); System.out.println("ErrorCode:"+es.getErrorCode()); es=es.getNextException(); } } catch(Exception es) { es.printStackTrace(); } finally { try { if(statement!=null) { statement.close(); } if(connection!=null) { connection.close(); } } catch(SQLException es) { System.out.println("\nERROR:-------SQLException-------\n"); System.out.println("Message:"+es.getMessage().toString()); System.out.println("SQLState:"+es.getSQLState().toString()); System.out.println("ErrorCode:"+es.getErrorCode()); } } } }

2005-08-28 12:37
快速回复:集合到入到表
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.027308 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved