《景点售票系统源代码》由会员分享,可在线阅读,更多相关《景点售票系统源代码(27页珍藏版)》请在金锄头文库上搜索。
1、import java.awt.Dimension;import java.awt.GridLayout;import java.awt.Toolkit;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;import javax.s
2、wing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JPasswordField;import javax.swing.JTextField;public class LogOnpublic static void main(String args)throws SQLExceptionfinal JFrame jfrmlogin=new JFrame( 系统登录 )
3、;jfrmlogin.setSize(400,280);Dimension screenSize=Toolkit.getDefaultToolkit().getScreenSize();jfrmlogin.setLocation(int) (screenSize.width-400)/2,(int)(screenSize.height-300)/2);/ 置框出现的位置JPanel p1=new JPanel();p1.add(new JLabel( 用户名: );final JTextField jtxtuser=new JTextField(14);JPanel p2=new JPanel
4、();p2.add(new JLabel( 密 码: );final JPasswordField jspwd=new JPasswordField(14);JPanel p3=new JPanel();final JButton jbtUser=new JButton( 登 录 );final JButton jbtreg=new JButton( 注 册 );JButton jbtexit=new JButton( 退 出 );p1.add(jtxtuser);p2.add(jspwd);p3.add(jbtUser);p3.add(jbtreg);p3.add(jbtexit);jbtU
5、ser.addActionListener(new ActionListener()public void actionPerformed(ActionEvent e)Connection conn=null;ResultSet rs=null;Statement stmt=null;if(e.getSource()=jbtUser)try Class.forName(oracle.jdbc.driver.OracleDriver);conn = DriverManager.getConnection(jdbc:oracle:thin:localhost:1521:orcl, system,
6、123);stmt=conn.createStatement();String USER_NAME=jtxtuser.getText();rs = stmt.executeQuery(select * from TICKET_USERSwhereUSER_NAME=+jtxtuser.getText()+and USER_PWD=+jspwd.getText()+);if(rs.next()if(USER_NAME.equals(admin)=false)MainUser mf=new MainUser();mf.setVisible(true);jfrmlogin.dispose();els
7、eMainFrame mf=new MainFrame();mf.setVisible(true);jfrmlogin.dispose();elseJOptionPane.showMessageDialog(null, 用户名或密码不一致, 请重新输入! , 系统提示 ,JOptionPane.ERROR_MESSAGE);jtxtuser.setText();jspwd.setText(); catch (Exception ex) JOptionPane.showMessageDialog(null, 用户名或密码不一致,请 重新输入! , 系统提示 ,JOptionPane.ERROR_
8、MESSAGE);jtxtuser.setText();jspwd.setText(););jbtreg.addActionListener(new ActionListener()public void actionPerformed(ActionEvent e)Connection conn=null;ResultSet rs=null;Statement stmt=null; if(e.getSource()=jbtreg)try Class.forName(oracle.jdbc.driver.OracleDriver); conn = DriverManager.getConnect
9、ion(jdbc:oracle:thin:localhost:1521:orcl, system, 123); stmt=conn.createStatement();rs = stmt.executeQuery(insert intoTICKET_USERS(USER_NAME,USER_PWD) values(+jtxtuser.getText()+,+jspwd.getText()+); if(rs.next()JOptionPane.showMessageDialog(null, 你已成功注册!可以 登录了! , 系统提示 ,JOptionPane.INFORMATION_MESSAG
10、E);jtxtuser.setText();jspwd.setText();elseJOptionPane.showMessageDialog(null, 用户注册失败! , 系 统提示 ,JOptionPane.ERROR_MESSAGE);jtxtuser.setText();jspwd.setText(); catch (Exception ex) JOptionPane.showMessageDialog(null, 用户注册失败! , 系统提 示 ”,JOptio nPa ne.ERROR_MESSAGE);jtxtuser.setText();jspwd.setText(););
11、jbtexit.addActio nListe ner(new Actio nListe ner() public void action Performed(Acti onEvent e) System.exit(O););jfrmlogi n. getC onten tPa ne().setLayout (new GridLayout(3,1); jfrmlogi n. getC onten tPa ne().add(p1);jfrmlogi n. getC onten tPa ne().add(p2);jfrmlogi n. getC onten tPa ne().add(p3);jfr
12、mlogi n.setVisible(true);import java.sql.*;public class ConnectOraclethrowspublic static void connection(String args)SQLExcepti on /Conn ecti on conn=n ull;/Statement stmt=null;/ResultSet rs=n ull;/JDBC直连Oracle数据库加载驱动try System. out .println(” 正在连接数据库 ”);Class. forName (oracle.jdbc.driver.OracleDriv
13、er);/*conn 二*/DriverManager. getConnection (jdbc:oracle:thin:localhost:1521:orcl , system , 123);System. out .println(”已经连接到数据库.);/stmt二c onn .createStateme nt();stmt.executeQuery(insert intostude nt(STUID,STUNAME,SEX,AGE)values(0001, 李华,男,20);/rs=stmt.executeQuery(select * from STUDENT);/System.out
14、.pri ntl n(” stuID + StuName + Sex+ Age);/while(rs. next()int STUID=rs.getI nt(STUID);/Stri ng STUNAME=rs.getStri ng(STUNAME);/Stri ng SEX=rs.getStri ng(SEX);int AGE=rs.get In t(AGE);/System.out.pri ntln( +STUID+ +STUNAME+ +SEX+AGE);/System.out.pri ntl n(” STUID +STUID+ STUNAME+STUNAME+SEX+SEX+AGE+AGE);/ catch (Exception ex) /System.out.println(”出现的异常为 ” + ex);import java.awt.Recta ngle;import java.awt.eve nt.Act ion Eve nt; import java.awt.eve nt.Act ion Liste ner;import java.sql.C onn ecti on;import java.sql.DriverMa nager;import java.sql.