wppdennis
发贴: 7
积分: 0
|
于 2006-06-08 10:42
我要往数据库里面,添加内容.但是中文和字母都不能添加,而数字确可以为什么? 有没有人告诉我哦.谢谢了. class TJYH extends Frame implements ActionListener { JTextField text,text1; JButton button,button1; JPanel panel,panel1,panel2; GridLayout net1; TJYH() { super("添加用户"); setVisible(false); setBounds(130,130,300,200); net1=new GridLayout(3,1); setLayout(net1); text=new JTextField(10); text1=new JTextField(10); panel=new JPanel(); panel1=new JPanel(); panel2=new JPanel(); button=new JButton("确定"); button1=new JButton("重填"); add(panel);add(panel1); add(panel2); panel.add(new JLabel("输入要添加的用户:")); panel.add(text); panel1.add(new JLabel("输入密码:")); panel1.add(text1); panel2.add(button); panel2.add(button1); button.addActionListener(this); button1.addActionListener(this); addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent e) { setVisible(false);System.exit(0); } }); } public void actionPerformed(ActionEvent e) { if(e.getSource()==button) { try{DJ();} catch(SQLException ee){} } else if(e.getSource()==button1) { text.setText(null); text1.setText(null); } } public void DJ() throws SQLException { String s1=text.getText(), s2=text1.getText(); String temp="INSERT INTO 用户 VALUES("+s1+","+s2+")"; try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");} catch(ClassNotFoundException e){} Connection con=DriverManager.getConnection("jdbc:odbcL1","",""); Statement sql=con.createStatement(); sql.executeUpdate(temp); } }
|