当前位置: 代码迷 >> J2SE >> 弄了一天了,还是不行,吐血,该怎么处理
  详细解决方案

弄了一天了,还是不行,吐血,该怎么处理

热度:236   发布时间:2016-04-24 18:10:39.0
弄了一天了,还是不行,吐血
数据库表里有数据,但是就是不显示在文本框里,运行也不报错,感觉代码没写错啊,为什么呢?就是不显示数据。
Java code
import javax.swing.*;import java.awt.*;import java.awt.event.*;import javax.swing.table.*;import java.sql.*;import java.util.*;import java.util.Date;import java.io.*;public class CopyOfPerson extends JFrame implements ActionListener {        public String DBDRIVER = "oracle.jdbc.driver.OracleDriver";    public String DBURL= "jdbc:oracle:thin:@127.0.0.1:1521:orcl";    public String DBUSER = "scott";    public String DBPASS = "tiger";    public Connection conn = null;    public PreparedStatement psmt = null;    public ResultSet rs = null;    int count;//记录更新的记录数    private JTextField jtxt, jtxt1, jtxt2, jtxt3, jtxt4, jtxt5, jtxt6, jtxt7,            jtxt8, jtxt15, jtxt17, jtxt18, jtxt20;    private JLabel jlAarray = new JLabel("职工ID");    private JLabel jlAarray1 = new JLabel("姓名");    private JLabel jlAarray2 = new JLabel("性别");    private JLabel jlAarray3 = new JLabel("出生年月");    private JLabel jlAarray4 = new JLabel("民族");    private JLabel jlAarray5 = new JLabel("籍贯");    private JLabel jlAarray6 = new JLabel("学历");    private JLabel jlAarray7 = new JLabel("学位");    private JLabel jlAarray8 = new JLabel("专业");    private JLabel jlAarray15 = new JLabel("毕业学校");    private JLabel QLb = new JLabel("请输入工号:");    // private JLabel jlAarray19 = new JLabel("照片路径");    private JLabel lblNewLabel = new JLabel("员工档案");    private JLabel lblNewLabel_2 = new JLabel("住宅电话");    private JLabel lblNewLabel_3 = new JLabel("手机");    private JLabel lblNewLabel_4 = new JLabel("浏览按钮");    JButton jbArray = new JButton("最前");    JButton jbArray1 = new JButton("上一个");    JButton jbArray2 = new JButton("下一个");    JButton jbArray3 = new JButton("最后");    private final JLabel label = new JLabel("\u5BB6\u5EAD\u4F4F\u5740");    private final JTextField jtxt16 = new JTextField();    private JTextField tf = new JTextField();;    JButton QBtn = new JButton("查询");        // private JButton jbArray4 = new JButton("浏览照片");    public CopyOfPerson() {        setTitle("员工详细信息");        setIconImage(Toolkit.getDefaultToolkit().getImage(// 设置图标                "D:\\PersonManager\\image\\123.jpg"));        getContentPane().setLayout(null);        setDefaultCloseOperation(CopyOfPerson.DISPOSE_ON_CLOSE);        lblNewLabel.setBounds(24, 10, 54, 15);        getContentPane().add(lblNewLabel);        jlAarray.setBounds(78, 111, 54, 15);// 职工ID        getContentPane().add(jlAarray);        jtxt = new JTextField();        jtxt.setBounds(142, 108, 144, 21);        jtxt.setEditable(false);        getContentPane().add(jtxt);        jlAarray1.setBounds(307, 111, 54, 15);// 姓名        getContentPane().add(jlAarray1);        jtxt1 = new JTextField();        jtxt1.setBounds(347, 108, 144, 21);        jtxt1.setEditable(false);        getContentPane().add(jtxt1);        jlAarray2.setBounds(501, 111, 54, 15);        getContentPane().add(jlAarray2);        jtxt2 = new JTextField();        jtxt2.setColumns(10);        jtxt2.setBounds(540, 108, 144, 21);        jtxt2.setEditable(false);        getContentPane().add(jtxt2);        jlAarray3.setBounds(78, 152, 54, 15);        getContentPane().add(jlAarray3);        jtxt3 = new JTextField();        jtxt3.setColumns(10);        jtxt3.setBounds(142, 149, 144, 21);        jtxt3.setEditable(false);        getContentPane().add(jtxt3);        jlAarray4.setBounds(307, 155, 54, 15);        getContentPane().add(jlAarray4);        jtxt4 = new JTextField();        jtxt4.setColumns(10);        jtxt4.setBounds(347, 152, 144, 21);        jtxt4.setEditable(false);        getContentPane().add(jtxt4);        jlAarray5.setBounds(501, 155, 54, 15);        getContentPane().add(jlAarray5);        jtxt5 = new JTextField();        jtxt5.setColumns(10);        jtxt5.setBounds(540, 152, 144, 21);        jtxt5.setEditable(false);        getContentPane().add(jtxt5);        jlAarray6.setBounds(78, 196, 54, 15);        getContentPane().add(jlAarray6);        jtxt6 = new JTextField();        jtxt6.setColumns(10);        jtxt6.setBounds(142, 193, 144, 21);        jtxt6.setEditable(false);        getContentPane().add(jtxt6);        jlAarray7.setBounds(308, 196, 40, 15);        getContentPane().add(jlAarray7);        jtxt7 = new JTextField();        jtxt7.setColumns(10);        jtxt7.setBounds(347, 193, 144, 21);        jtxt7.setEditable(false);        getContentPane().add(jtxt7);        jlAarray8.setBounds(501, 196, 54, 15);        getContentPane().add(jlAarray8);        jtxt8 = new JTextField();        jtxt8.setColumns(10);        jtxt8.setBounds(540, 193, 144, 21);        jtxt8.setEditable(false);        getContentPane().add(jtxt8);        jlAarray15.setBounds(78, 238, 54, 15);        getContentPane().add(jlAarray15);        jtxt15 = new JTextField();        jtxt15.setColumns(10);        jtxt15.setBounds(142, 235, 542, 21);        jtxt15.setEditable(false);        getContentPane().add(jtxt15);        jtxt17 = new JTextField();        jtxt17.setColumns(10);        jtxt17.setBounds(142, 315, 144, 21);        jtxt17.setEditable(false);        getContentPane().add(jtxt17);        jtxt18 = new JTextField();        jtxt18.setColumns(10);        jtxt18.setBounds(347, 315, 144, 21);        jtxt18.setEditable(false);        getContentPane().add(jtxt18);        lblNewLabel_2.setBounds(77, 318, 65, 15);        getContentPane().add(lblNewLabel_2);        lblNewLabel_3.setBounds(307, 318, 54, 15);        getContentPane().add(lblNewLabel_3);        lblNewLabel_4.setBounds(78, 359, 54, 15);        getContentPane().add(lblNewLabel_4);        jbArray.setBounds(89, 396, 93, 23);        getContentPane().add(jbArray);        jbArray1.setBounds(223, 396, 93, 23);        getContentPane().add(jbArray1);        jbArray2.setBounds(347, 396, 93, 23);        getContentPane().add(jbArray2);        jbArray3.setBounds(483, 396, 93, 23);        getContentPane().add(jbArray3);        label.setBounds(78, 279, 54, 15);        getContentPane().add(label);        jtxt16.setColumns(10);        jtxt16.setBounds(142, 276, 542, 21);        jtxt16.setEditable(false);        getContentPane().add(jtxt16);        QLb.setBounds(56, 49, 76, 15);        getContentPane().add(QLb);                tf.setBounds(142, 47, 144, 18);        getContentPane().add(tf);        tf.setColumns(10);        QBtn.setBounds(303, 45, 93, 23);        getContentPane().add(QBtn);        QBtn.addActionListener(new ActionListener() {            public void actionPerformed(ActionEvent e) {                searchPerson();            }        });        // 注册监听//        jbArray.addActionListener(this);//        jbArray1.addActionListener(this);//        jbArray2.addActionListener(this);//        jbArray3.addActionListener(this);        // jbArray4.addActionListener(this);        //db = new DataBase1();        //vtemp = db.getPerson();// 调用getPerson方法以获得职工信息        // image = db.getPic();// 获得照片信息        //db.dbClose();        this.setBounds(5, 5, 828, 509);// 设置窗体的大小位置        this.setVisible(true); // 设置窗体的可见性    }    // 获得图片        public void actionPerformed(ActionEvent e) {            }    public void searchPerson() {            String sql1 = "select employeeid,p_name,sex,p_birthday,city,nation,culture,graduate,graduate_school,spec,family_address,family_tel,mobile_tel from tbl_pw_main where employeeid=?";            String id = tf.getText().toString().trim();            try {                Class.forName(DBDRIVER);                conn = DriverManager.getConnection(DBURL,DBUSER,DBPASS);            } catch (Exception e) {                e.printStackTrace();            }            try{                psmt = conn.prepareStatement(sql1);                psmt.setString(1, id);                rs = psmt.executeQuery();                while(rs.next()) {                    String str1 = rs.getString(1);                    String str2 = rs.getString(2);                    String str3 = rs.getString(3);                    String str4 = rs.getString(4);                    String str5 = rs.getString(5);                    String str6 = rs.getString(6);                    String str7 = rs.getString(7);                    String str8 = rs.getString(8);                    String str9 = rs.getString(9);                    String str10 = rs.getString(10);                    String str11 = rs.getString(11);                    String str12 = rs.getString(12);                    String str13 = rs.getString(13);                    jtxt.setText(str1);                    jtxt1.setText(str2);                    jtxt2.setText(str3);                    jtxt3.setText(str4);                    jtxt4.setText(str5);                    jtxt5.setText(str6);                    jtxt6.setText(str7);                    jtxt7.setText(str8);                    jtxt8.setText(str9);                    jtxt15.setText(str10);                    jtxt16.setText(str11);                    jtxt17.setText(str12);                    jtxt18.setText(str13);                }                rs.close();                psmt.close();                conn.close();                                } catch (SQLException e) {                                        e.printStackTrace();                }                    }        public static void main(String[] args) {        new CopyOfPerson();    }}
  相关解决方案