Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Database/JDBC/SQL/JDO/Hibernate  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 为什么不能插入中文
wppdennis





发贴: 7
积分: 0
于 2006-06-08 10:42 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
我要往数据库里面,添加内容.但是中文和字母都不能添加,而数字确可以为什么?
有没有人告诉我哦.谢谢了.
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:odbcBig SmileL1","","");
    Statement sql=con.createStatement();
   sql.executeUpdate(temp);
    
  }
}



作者 Re:为什么不能插入中文 [Re:wppdennis]
kyderen





发贴: 1
积分: 0
于 2006-06-10 23:35 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
我也碰到了这样的问题,可能是数据库驱动有问题吧


看你的数据类型有没有设置对,中文是Nvarchar类型的


那位大哥来帮个忙啊,小弟先谢了


why edited on 2006-06-11 06:11

作者 Re:为什么不能插入中文 [Re:wppdennis]
256456





发贴: 91
积分: 50
于 2006-06-20 10:47 user profilesend a private message to usersend email to 256456search all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
兄弟,你的表名怎么也用中文呀,是什么数据库,Access or SQL Server ?



flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923