火车售票 第2

时间:2015-07-15 10:57:12
【文件属性】:

文件名称:火车售票 第2

文件大小:3KB

文件格式:JAVA

更新时间:2015-07-15 10:57:12

java 火车 售票

import java.awt.Color; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import javax.swing.*; public class CheCiXiangQin extends JFrame { Connection con = null; Statement stmt = null; ResultSet rs = null; String[] str=new String[20]; JLabel[] jpx=new JLabel[20]; JPanel jp=new JPanel(); JButton jb1=new JButton("确定"); JButton jb2=new JButton("订票"); public CheCiXiangQin(){ super("车次查询"); setSize(900,700); this.setVisible(true); jp.setLayout(null); jp.setBounds(10, 10, 880, 680); jp.setBackground(Color.WHITE); add(jp); for(int k=0;k<12;k++){ jpx[k]=new JLabel(); } try { Class.forName("oracle.jdbc.driver.OracleDriver"); } catch (ClassNotFoundException e) {} String url = "jdbc:oracle:thin:@192.168.5.16:1521:lieche"; String user = "system"; String password = "111111"; try {con = DriverManager.getConnection(url, user, password); stmt = con.createStatement(); } catch (SQLException e) { e.printStackTrace(); } } //查询方法 public ResultSet query(String sql){ try { rs = stmt.executeQuery(sql); } catch (SQLException e) {} return rs; } public void action(String sql) { int count=0; rs = query(sql); try { while(rs.next()){ //遍历取出结果集中的内容 str[count]=rs.getString(1)+" "+rs.getString(2)+" "+rs.getString(3)+" "+rs.getString(4)+" "+rs.getString(5)+" "+rs.getString(6)+" "+rs.getString(7)+ " "+rs.getString(8)+" "+rs.getString(9)+" "+rs.getString(10)+" "+rs.getString(11)+" "+rs.getString(12)+" "+rs.getString(13)+" "+rs.getString(14)+" "+rs.getString(15)+" "+rs.getString(16); count++; } } catch (SQLException se) { se.printStackTrace(); } for(int i=0;i<12;i++) { if(i==0) { jpx[0].setText("车次 "+"类型 "+"始发站 "+"始发时间 "+"终点站 "+"站点 "+"到达时间 "+"发车时间 "+"路程 "+" 总票"+" 第0天剩余"+" 第1天剩余"+" 第2天剩余"+" 第3天剩余"+" 第4天剩余"+" 第5天剩余"); jp.add(jpx[0]); jpx[0].setBounds(10, 20, 900,20); } else{ jpx[i].setText(str[i-1]); jp.add(jpx[i]); jpx[i].setBounds(10, 40*(i+1)-30, 900, 20); } } jp.add(jb1); jb1.setBounds(350, 500, 100, 50); jb1.addMouseListener(new MouseAdapter(){ public void mouseReleased(MouseEvent e) { setVisible(false); } }); jp.add(jb2); jb2.setBounds(500, 500, 100, 50); } public void close(){ try { rs.close(); } catch (SQLException e) {} try { stmt.close(); } catch (SQLException e) {} try { con.close(); } catch (SQLException e) {} } }


网友评论