CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
可用分押宝游戏火热进行中... 专题改版:Java Web 专题
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  Java >  Web 开发

我这样写SQL有错吗?

楼主xiejing1981314(新手)2005-04-03 21:42:33 在 Java / Web 开发 提问

try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");  
        }  
  catch(ClassNotFoundException   e)  
  {System.out.print(e);  
        }  
  try   {con=DriverManager.getConnection("jdbc:odbc:jxpt","","");  
  sql=con.createStatement();  
  String   condition="INSERT   INTO   student   (id,name,password,mail,phone,contact,sex,postcode)   VALUES(id,realName,password1,mail,phone,contact,sex,postcode)";  
  sql.executeUpdate(condition);  
     
    }  
  catch(SQLException   e)  
  {  
  this.re=false;  
  System.out.println(e);  
    }  
  return   this.re;  
     
  }    
  我在运行时出现java.sql.SQLException:[Microsoft][ODBC   Microsoft   Access   Driver]参数不足,期待是8  
  这是什么原因呀?  
   
  问题点数:20、回复次数:9Top

1 楼jFresH_MaN(十一月的萧邦-夜曲)回复于 2005-04-03 21:46:02 得分 20

String   condition="INSERT   INTO   student   (id,name,password,mail,phone,contact,sex,postcode)   VALUES(id,realName,password1,mail,phone,contact,sex,postcode)";  
  ----------  
  values里面如果是字符或者字符串型的必须用单引号‘  
   
  比如  
  insert   into   tableName   (name)   values('ccc');Top

2 楼SunnyTomorrow(SunnyTomorrow)回复于 2005-04-03 22:57:08 得分 0

唉。。。不知道怎么说你Top

3 楼xiejing1981314(新手)回复于 2005-04-03 22:58:11 得分 0

如果是布尔值不用加吧.Top

4 楼xiejing1981314(新手)回复于 2005-04-03 22:59:25 得分 0

想怎么说都行,菜鸟一只.:(Top

5 楼xiejing1981314(新手)回复于 2005-04-03 23:14:20 得分 0

对字符串型加了'编译成功了.  
   
  可是对数据库插不进数据.郁闷!~~~Top

6 楼joyaga(joyaga)回复于 2005-04-04 09:23:57 得分 0

你把源文件都贴出来帮你看看  
  Top

7 楼xiejing1981314(新手)回复于 2005-04-04 09:30:48 得分 0

好的.全部的代码.  
  /*  
    *   Created   on   2005-3-29  
    *  
    *   To   change   the   template   for   this   generated   file   go   to  
    *   Window>Preferences>Java>Code   Generation>Code   and   Comments  
    */  
  package   bean;  
  import   java.sql.*;  
  import   java.util.ArrayList;  
  import   org.apache.struts.action.ActionError;  
  import   org.apache.struts.action.ActionErrors;  
   
   
  /**  
    *   @author   xiejing  
    *  
    *   To   change   the   template   for   this   generated   type   comment   go   to  
    *   Window>Preferences>Java>Code   Generation>Code   and   Comments  
    */  
  public   class   UserinfoBean   {  
    private   String   id="";  
    private   String   realName="";  
    private   String   password1="";  
    private   String   phone="";  
    private   String   mail="";  
    private   String   sex="";  
    private   String   address="";  
                      private   String   postcode="";  
    private   Connection   con=null;    
    private   Statement   sql=null;  
    private   boolean   re=true;    
    private   ResultSet   rs=null;  
    public   boolean   register(String   n1,String   n2,String   n3,String   n4,String   n5,String   n6,String   n7,   String   n8)   {  
  this.id=n1;  
  this.realName=n2;  
  this.password1=n3;  
                    this.sex=n4;  
  this.phone=n5;  
  this.address=n6;  
  this.mail=n7;  
                                      this.postcode=n8;  
  try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");  
        }  
      catch(ClassNotFoundException   e)  
        {   //System.out.print(e);  
          e.printStackTrace();  
        }  
  try   {   con=DriverManager.getConnection("jdbc:odbc:jxpt","","");  
      sql=con.createStatement();  
      String   condition="INSERT   INTO   student   (id,name,password,mail,phone,contact,sex,postcode)   VALUES('"+n1+"','"+n2+"','"+n3+"','"+n7+"','"+n5+"','"+n6+"','"+n4+"','"+n8+"')";  
      int   rows=sql.executeUpdate(condition);  
      System.out.println("rows   is:"   +rows);  
    }  
    catch(SQLException   e)  
    {  
  this.re=false;  
  //System.out.println(e);  
          e.printStackTrace();  
    }  
    return   this.re;  
     
  }    
   
  public   static   void   main(String[]   args)   {  
    UserinfoBean   ub=new   UserinfoBean();  
    boolean   b=ub.register(   "sy0406630","xiaozhan","6202637","M","82337280","buaa","xiaozhan@163.com","100082");  
    System.out.print(b);  
    }  
     
   
   
  }  
  最后的输出结果是:rows   is:1  
                                    true  
  可是数据没有加入到数据库中.Top

8 楼joyaga(joyaga)回复于 2005-04-04 09:41:25 得分 0

都   执行成功了   你看抛出什么错误没Top

9 楼wtiancai(博学,审问,慎思,明辨,笃行.)回复于 2005-04-04 09:51:08 得分 0

out.print(condition)  
   
  然后把这条语句拿到数据库里面运行,看能不能执行成功,不能执行它就会提示哪里出错了Top

相关问题

  • SQL 语句这样写为什么会错
  • 这样的SQL如何写
  • 这样的SQL如何写?
  • 这样的T-SQL怎么写?
  • 这样的sql怎么写?
  • sql可以这样写吗?
  • 这样的sql怎样写?
  • 这样的sql怎么写
  • 这样的SQL怎么写?
  • 这样的sql怎么写?

关键词

  • code
  • sql
  • postcode
  • sex
  • contact
  • phone
  • condition
  • odbc
  • mail
  • generation

得分解答快速导航

  • 帖主:xiejing1981314
  • jFresH_MaN

相关链接

  • CSDN Java频道
  • Java类图书
  • Java类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
世纪乐知(北京)网络技术有限公司 版权所有, 京 ICP 证 020026 号
北京创新乐知广告有限公司 提供技术支持
Copyright © 2000-2007, CSDN.NET, All Rights Reserved
GongshangLogo