import java.sql.*; import java.io.*; import java.awt.*; import java.awt.event.*; import java.util.*; import javax.swing.border.*;
public class EmployeepreparedStatement extends Frame implements Serializable { /*JTable table; Panel p; Object l[][],lieming[]={"货物ID号","货物名称","货物颜色","货物体积","货物价格","货物产地"}; public EmployeepreparedStatement() { p=new Panel(); LinkedList goodlist=(LinkedList)rs.readObject();//在集合当中怎样把数据库里面的数据读到集合中去 int length=goodlist.size(); l=new Object[length][6]; table=new JTable(l,lieming); p.removeAll(); p.add(new JScrollPane(table)); p.validate(); Iterator iter=goodlist.iterator(); int i=0; while(iter.hasNext()) { EmployeepreparedStatement gds=(EmployeepreparedStatement)iter.next(); l[1][0]=EmployeepreparedStatement. setSize(500,300); setVisible(true); */ public static void main(String args[]) { int id; String name; String color; int higth; int price; String address; try { Statement smt; Connection con; System.out.println("正在追被连接"); Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); con=DriverManager.getConnection("jdbc:odbc:MyServer"); Statement sm=con.createStatement(); ResultSet rs=sm.executeQuery("select itemId,itemName,itemColor,itemHight,itemPrice,itemAddress from itemtable" ); while(rs.next()) { id=rs.getInt("itemId"); name=rs.getString("itemName"); color=rs.getString("itemColor"); higth=rs.getInt("itemHight"); price=rs.getInt("itemPrice"); address=rs.getString("itemAddress"); System.out.println(id+"\t"+name+"\t"+color+"\t"+higth+"\t"+address+"\t"+price); } sm.close(); con.close(); } catch(Exception e) { System.out.println(e.toString()); } EmployeepreparedStatementd(); JTable table; Panel p; Object l[][],lieming[]={"货物ID号","货物名称","货物颜色","货物体积","货物价格","货物产地"}; public void EmployeepreparedStatementd() { try { p=new Panel(); LinkedList goodlist=(LinkedList)rs.readObject();//在集合当中怎样把数据库里面的数据读到集合中去 int length=goodlist.size(); l=new Object[length][6]; table=new JTable(l,lieming); p.removeAll(); p.add(new JScrollPane(table)); p.validate(); Iterator iter=goodlist.iterator(); int i=0; while(iter.hasNext()) { EmployeepreparedStatement gds=(EmployeepreparedStatement)iter.next(); l[i][0]=id; l[i][1]=name; l[i][2]=color; l[i][3]=higth; l[i][4]=price; l[i][5]=address; i++; } table.repaint(); } catch(Exception ee) { System.out.println(ee.toString()); } setSize(500,300); setVisible(true); } } }