用户名不能输入数字和字母,
//怎么没有结果输出谁能帮我处理以下 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()); } } } }