📄 frame2.java~53~
字号:
package untitled5;import java.io.*;import java.net.*;import java.sql.*;import java.lang.*;import javax.sql.*;import java.awt.*;import java.awt.event.*;import javax.swing.*;import com.borland.jbcl.layout.*;import com.borland.dbswing.*;//货品信息登记public class Frame2 extends JFrame { JPanel contentPane; JLabel jLabel1 = new JLabel(); XYLayout xYLayout1 = new XYLayout(); JLabel jLabel2 = new JLabel(); JLabel jLabel3 = new JLabel(); JTextField jTextField1 = new JTextField(); JLabel jLabel4 = new JLabel(); JTextField jTextField2 = new JTextField(); JPanel jPanel1 = new JPanel(); XYLayout xYLayout2 = new XYLayout(); JScrollPane jScrollPane1 = new JScrollPane(); JLabel jLabel5 = new JLabel(); JTextField jTextField3 = new JTextField(); //Construct the frame public Frame2() { enableEvents(AWTEvent.WINDOW_EVENT_MASK); try { jbInit(); } catch(Exception e) { e.printStackTrace(); } } //Component initialization private void jbInit() throws Exception { contentPane = (JPanel) this.getContentPane(); contentPane.setLayout(xYLayout1); this.setSize(new Dimension(600, 500)); this.setTitle("销售管理系统"); this.addHierarchyBoundsListener(new Frame2_this_hierarchyBoundsAdapter(this)); jLabel1.setFont(new java.awt.Font("SansSerif", 0, 25)); jLabel1.setForeground(Color.red); jLabel1.setText("销售管理系统"); contentPane.setForeground(Color.black); jLabel2.setFont(new java.awt.Font("SansSerif", 0, 30)); jLabel2.setText("产 品 信 息 展 示"); // statusBar.setFont(new java.awt.Font("SansSerif", 0, 20)); jLabel3.setFont(new java.awt.Font("SansSerif", 0, 20)); jLabel3.setText("产品名称"); jTextField1.setText(""); jLabel4.setEnabled(true); jLabel4.setFont(new java.awt.Font("SansSerif", 0, 20)); jLabel4.setText("产品ID号"); jTextField2.setText(""); jTextField2.addActionListener(new Frame2_jTextField2_actionAdapter(this)); jPanel1.setLayout(xYLayout2); jLabel5.setFont(new java.awt.Font("SansSerif", 0, 25)); jLabel5.setForeground(Color.red); jLabel5.setText("该产品详细信息"); jTextField3.setText(""); contentPane.add(jLabel1, new XYConstraints(237, 0, 153, 40)); contentPane.add(jLabel2, new XYConstraints(200, 47, 231, 58)); contentPane.add(jLabel3, new XYConstraints(47, 102, 101, 42)); contentPane.add(jTextField1, new XYConstraints(128, 108, 112, 34)); contentPane.add(jTextField2, new XYConstraints(361, 107, 109, 36)); contentPane.add(jPanel1, new XYConstraints(75, 166, 453, 277)); jPanel1.add(jScrollPane1, new XYConstraints(14, 8, 433, 221)); jScrollPane1.getViewport().add(jTextField3, null); jPanel1.add(jLabel5, new XYConstraints(112, 240, -1, -1)); contentPane.add(jLabel4, new XYConstraints(278, 111, -1, -1)); } //Overridden so we can exit when window is closed protected void processWindowEvent(WindowEvent e) { super.processWindowEvent(e); if (e.getID() == WindowEvent.WINDOW_CLOSING) { System.exit(0); } } void Select() { try { String str1, str2; str1 = jTextField1.getText(); str2 = jTextField2.getText(); //装载jdbc驱动程序 String driverName = "oracle.jdbc.OracleDriver"; Driver driver = (Driver) Class.forName(driverName).newInstance(); //连接数据库 Connection con = DriverManager.getConnection( "jdbc:oracle:thin:@thsspc0791:1521:liuyong", "sa", "tongfang"); PreparedStatement pstmt = con.prepareStatement( " select Good('ID','name' ,'quality','price') where ID=? and name=? "); pstmt.setString(1, str1); pstmt.setString(2, str2); ResultSet res = pstmt.executeQuery(); //String sa=res.getString(1); String outputarea=" Id " +" Name "+" quality "+" price "+"\n"; do{ outputarea+=" "+res.getString(1)+" "+" "+res.getString(2)+" "+" "+res.getString(3)+" "+" "+res.getInt(4)+" "+" "+res.getString(5)+" "+" "+res.getString(6)+" "+" "+res.getInt(7)+" "+"\n"; jTextField3.setText(outputarea); }while (res.next()); }catch (InstantiationException e) { System.out.println(e.getMessage()); }catch (IllegalAccessException e) { System.out.println(e.getMessage()); }catch (ClassNotFoundException e) { System.out.println(e.getMessage()); }catch (SQLException edd) { edd.printStackTrace() ; System.out.println(edd.getMessage()); } } void validID() { try { String str1, str2; str1 = jTextField1.getText(); str2 = jTextField2.getText(); //装载jdbc驱动程序。 //通过下面的程序我们完成对oracle数据库的动态连接。 String driverName = "oracle.jdbc.OracleDriver"; Driver driver = (Driver) Class.forName(driverName).newInstance(); //连接数据库 //在下面的程序中我们连接的数据库是名为“tongfang“的数据库 //登录名是”sa“密码是“tongfang” Connection con = DriverManager.getConnection( "jdbc:oracle:thin:@thsspc0791:1521:liuyong", "sa", "tongfang"); //执行动态的sql语句 PreparedStatement pstmt = con.prepareStatement( //依据读者的名字查询读者的信息的sql语句 " select name ,id,password from worker-info where name=?"); //将读者的名字添加到具体的sql语句中 pstmt.setString(1, str1); //使用ResultSet中的方法executeQuery()来完成sql语句的执行 ResultSet res = pstmt.executeQuery(); //使用getString()来获取sql查询的结果 //String sa=res.getString(1); if ((!res.next()) || res.getString("password") == null) { JOptionPane.showMessageDialog(this, "查无此人", "错误", JOptionPane.ERROR_MESSAGE); }else { if ( !res.getString("password").equals(str2)) { JOptionPane.showMessageDialog(this, "密码错误", "错误", JOptionPane.ERROR_MESSAGE); }else { System.out.println("zhengque"); do{ System.out.println(res.getString(1)+":" + res.getString(2) + ":" +res.getString(3)); }while (res.next()); } } pstmt.close(); con.close(); }catch (InstantiationException e) { System.out.println(e.getMessage()); }catch (IllegalAccessException e) { System.out.println(e.getMessage()); }catch (ClassNotFoundException e) { System.out.println(e.getMessage()); }catch (SQLException edd) { edd.printStackTrace() ; System.out.println(edd.getMessage()); } } void this_ancestorMoved(HierarchyEvent e) { } void jTextField2_actionPerformed(ActionEvent e) { validID(); Select(); }}class Frame2_this_hierarchyBoundsAdapter extends java.awt.event.HierarchyBoundsAdapter { Frame2 adaptee; Frame2_this_hierarchyBoundsAdapter(Frame2 adaptee) { this.adaptee = adaptee; } public void ancestorMoved(HierarchyEvent e) { adaptee.this_ancestorMoved(e); }}class Frame2_jTextField2_actionAdapter implements java.awt.event.ActionListener { Frame2 adaptee; Frame2_jTextField2_actionAdapter(Frame2 adaptee) { this.adaptee = adaptee; } public void actionPerformed(ActionEvent e) { adaptee.jTextField2_actionPerformed(e); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -