大家帮我看看:打印isadd()是FALSE,怎么回事!
public boolean add() {
strSql = "insert into users";
strSql = strSql + "(";
strSql = strSql + "userName,";
strSql = strSql + "userPassword,";
strSql = strSql + "email,";
strSql = strSql + "sex,";
strSql = strSql + "identityID,";
strSql = strSql + "shopName,";
strSql = strSql + "shopIntro,";
strSql = strSql + "shopper,";
strSql = strSql + "realName,";
strSql = strSql + "mainFields,";
strSql = strSql + "telephone,";
strSql = strSql + "createDate,";
strSql = strSql + "sysRole,";
strSql = strSql + "tag";
strSql = strSql + ")";
strSql = strSql + "values (";
strSql = strSql + "'" + userName + "'";
strSql = strSql + "'" + userPassword + "'";
strSql = strSql + "'" + email + "'";
strSql = strSql + "'" + sex +"'";
strSql = strSql + "'" + identityID + "'";
strSql = strSql + "'" + shopName + "'";
strSql = strSql + "'" + shopIntro + "'";
strSql = strSql + "'" + shopper + "'";
strSql = strSql + "'" + realName + "'";
strSql = strSql + "'" + mainFields + "'";
strSql = strSql + "'" + telephone + "'";
strSql = strSql + "'" + createDate + "'";
strSql = strSql + "'" + sysRole + "'";
strSql = strSql + "'" + tag + "'";
strSql = strSql + ")";
System.out.println(strSql);
boolean isAdd = super.exeSqlUpdate(strSql);
System.out.println(isAdd);
return isAdd; }
当转到jsp页面后,老是注册失败 if(isAdd) {
out.println("用户注册成功!");
}
else {
out.println("用户注册失败!");
}
public boolean add() {
strSql = "insert into users";
strSql = strSql + "(";
strSql = strSql + "userName,";
strSql = strSql + "userPassword,";
strSql = strSql + "email,";
strSql = strSql + "sex,";
strSql = strSql + "identityID,";
strSql = strSql + "shopName,";
strSql = strSql + "shopIntro,";
strSql = strSql + "shopper,";
strSql = strSql + "realName,";
strSql = strSql + "mainFields,";
strSql = strSql + "telephone,";
strSql = strSql + "createDate,";
strSql = strSql + "sysRole,";
strSql = strSql + "tag";
strSql = strSql + ")";
strSql = strSql + "values (";
strSql = strSql + "'" + userName + "'";
strSql = strSql + "'" + userPassword + "'";
strSql = strSql + "'" + email + "'";
strSql = strSql + "'" + sex +"'";
strSql = strSql + "'" + identityID + "'";
strSql = strSql + "'" + shopName + "'";
strSql = strSql + "'" + shopIntro + "'";
strSql = strSql + "'" + shopper + "'";
strSql = strSql + "'" + realName + "'";
strSql = strSql + "'" + mainFields + "'";
strSql = strSql + "'" + telephone + "'";
strSql = strSql + "'" + createDate + "'";
strSql = strSql + "'" + sysRole + "'";
strSql = strSql + "'" + tag + "'";
strSql = strSql + ")";
System.out.println(strSql);
boolean isAdd = super.exeSqlUpdate(strSql);
System.out.println(isAdd);
return isAdd; }
当转到jsp页面后,老是注册失败 if(isAdd) {
out.println("用户注册成功!");
}
else {
out.println("用户注册失败!");
}
解决方案 »
- 请教高手如何写一个类似jQuery一样包装的JavaScript对象
- 这个链接的文件在哪里?
- JS分别给数组元素加onclick,出现些小问题,求解~
- 关于鼠标取词技术的程序语言的使用疑惑!
- 有没有办法为网页中的对象RENAME??
- IE6.0打印问题?
- svg浏览器兼容问题
- 请帮忙:怎样用代码实现当选中或经过表格行时被选中或向下的效果(像按钮被按下的那种效果!)
- 如何实现页面定时刷新,功能同与于ie的f5??
- 在带有form表单提交的页面中,refresh页面时老是弹出,"不重新发送信息,则无法刷新网页",请问怎样才能在不再发送信息的情况下,刷新页面
- flash 反复播放咋整???在线!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- 各位高手,我刚学完J2se,我想以后开发Web,现在正在学javaScript不要知道要学到什么程度才行,谢谢!
{
//将sql语句定义为insert,学过数据库应该能明白
strSql="insert into company_inf ";
strSql=strSql + "(";
strSql=strSql + "username,";
strSql=strSql + "userpassword,";
strSql=strSql + "e_mail,";
strSql=strSql + "area,";
strSql=strSql + "address,";
strSql=strSql + "phone,";
strSql=strSql + "zipcode,";
strSql=strSql + "website,";
strSql=strSql + "content,";
strSql=strSql + "mappoint";
strSql=strSql +") ";
strSql=strSql +"values (";
strSql=strSql + "'"+ username +"',";
strSql=strSql + "'"+ userpassword +"',";
strSql=strSql + "'"+ e_mail +"',";
strSql=strSql + "'"+ area +"',";
strSql=strSql + "'"+ address +"',";
strSql=strSql + "'"+ phone +"',";
strSql=strSql + "'"+ zipcode +"',";
strSql=strSql + "'"+ website +"',";
strSql=strSql + "'"+ content + "',";
strSql=strSql + "'"+ mappoint+"'";
strSql=strSql + ");";
//输出sql语句,主要是用来看看sql语句是否正确
System.out.println(strSql);
//调用Operator的exeSqlUpdate(String s)方法执行插入操作
boolean isAdd =super.exeSqlUpdate(strSql);
return isAdd;
}
}
strSql = strSql + "(";
strSql = strSql + "userName,"; //这里的,好像是中文状态下的
strSql = strSql + "userPassword,";
strSql = strSql + "email,";
strSql = strSql + "sex,";
strSql = strSql + "identityID,";
strSql = strSql + "shopName,";
strSql = strSql + "shopIntro,";
strSql = strSql + "shopper,";
strSql = strSql + "realName,";
strSql = strSql + "mainFields,";
strSql = strSql + "telephone,";
strSql = strSql + "createDate,";
strSql = strSql + "sysRole,";
strSql = strSql + "tag";
strSql = strSql + ")";
strSql = strSql + "values (";
strSql = strSql + "'" + userName + "',"; 下面应该这样,你没有加,
strSql = strSql + "'" + userPassword + "'";
strSql = strSql + "'" + email + "'";
strSql = strSql + "'" + sex +"'";
strSql = strSql + "'" + identityID + "'";
strSql = strSql + "'" + shopName + "'";
strSql = strSql + "'" + shopIntro + "'";
strSql = strSql + "'" + shopper + "'";
strSql = strSql + "'" + realName + "'";
strSql = strSql + "'" + mainFields + "'";
strSql = strSql + "'" + telephone + "'";
strSql = strSql + "'" + createDate + "'";
strSql = strSql + "'" + sysRole + "'";
strSql = strSql + "'" + tag + "'";
strSql = strSql + ")";
package operatedb; //文件打包到operatedb下 //导入需要的包
import java.sql.Connection;
import java.sql.*;
//定义一个类继承OpenDB
public class Operate extends OpenDB
{
//调用OpenDB的方法getConnection()返回一个Connection对象
private Connection dbconn=super.getConnection(); private Statement stmt=null;//将其该位于处理的方法
//private PreparedStatement pstmt=null;
private ResultSet rs=null; //定义一个结果集
private int errNum=0;
private String errDesc=""; //数据库更新方法
public boolean exeSqlUpdate(String strSql)
{
try
{
//pstmt=dbconn.prepareStatement(strSql);
//pstmt.executeUpdate();
stmt=dbconn.createStatement(); //获得操作对象
stmt.executeUpdate(strSql); //执行更新,具体内容看strSql
this.errNum=0;
return true;
}
catch(Exception ex)
{
this.errNum=-1;
this.errDesc=ex.toString(); //将异常信息赋给errDesc字符串
return false;
}
}
//返回errNum
public int getErrNum()
{
return errNum;
}
//返回errDesc
public String getErrDesc()
{
return errDesc;
}
}
package operatedb;
import java.sql.*;
import java.text.*;
//Users类继承Operate类
public class Users extends Operate
{ //变量对应数据库表中字段
public int ID;
public String username="";
public String userpassword="";
public String e_mail="";
public String area="";
public String address="";
public String phone="";
public String zipcode="";
public int sysRole=0;
public int tag =0;
public String website="";
public String content="";
public String mappoint="";
private SimpleDateFormat dateFormatter=new SimpleDateFormat("yy-MM-dd");
public String createDate=dateFormatter.format(new java.util.Date());
//存放sql语句
public String strSql=""; public boolean add()
{
//将sql语句定义为insert,学过数据库应该能明白
strSql="insert into company_inf ";
strSql=strSql + "(";
strSql=strSql + "username,";
strSql=strSql + "userpassword,";
strSql=strSql + "e_mail,";
strSql=strSql + "area,";
strSql=strSql + "address,";
strSql=strSql + "phone,";
strSql=strSql + "zipcode,";
strSql=strSql + "website,";
strSql=strSql + "content,";
strSql=strSql + "mappoint";
strSql=strSql +") ";
strSql=strSql +"values (";
strSql=strSql + "'"+ username +"',";
strSql=strSql + "'"+ userpassword +"',";
strSql=strSql + "'"+ e_mail +"',";
strSql=strSql + "'"+ area +"',";
strSql=strSql + "'"+ address +"',";
strSql=strSql + "'"+ phone +"',";
strSql=strSql + "'"+ zipcode +"',";
strSql=strSql + "'"+ website +"',";
strSql=strSql + "'"+ content + "',";
strSql=strSql + "'"+ mappoint+"'";
strSql=strSql + ");";
//输出sql语句,主要是用来看看sql语句是否正确
System.out.println(strSql);
//调用Operator的exeSqlUpdate(String s)方法执行插入操作
boolean isAdd =super.exeSqlUpdate(strSql);
return isAdd;
}
}
strSql=strSql + "'"+ username +"',"; 现在明白打印出来的sql语句为什么username是null了吗,改成上面的再打印一下sql语句试试
LZ下面每一句的后面都少加一个逗号
strSql = strSql + "values (";
strSql = strSql + "'" + userName + "'";
strSql = strSql + "'" + userPassword + "'";
strSql = strSql + "'" + email + "'";
strSql = strSql + "'" + sex +"'";
strSql = strSql + "'" + identityID + "'";
strSql = strSql + "'" + shopName + "'";
strSql = strSql + "'" + shopIntro + "'";
strSql = strSql + "'" + shopper + "'";
strSql = strSql + "'" + realName + "'";
strSql = strSql + "'" + mainFields + "'";
strSql = strSql + "'" + telephone + "'";
strSql = strSql + "'" + createDate + "'";
strSql = strSql + "'" + sysRole + "'";
strSql = strSql + "'" + tag + "'"; 你现在的语句是
insert into users (userName,userPassword,email,sex,identityID,shopName,shopIntro,shopper,realName,mainFields,telephone,createDate,sysRole,tag)
values
('userName''userPassword''email''sex''identityID''shopName''shopIntro''shopper''realName''mainFields''telehphone''createDate''sysRole''tag')正确应该如下
insert into users (userName,userPassword,email,sex,identityID,shopName,shopIntro,shopper,realName,mainFields,telephone,createDate,sysRole,tag)
values
('userName','userPassword','email','sex','identityID','shopName','shopIntro','shopper','realName','mainFields','telehphone','createDate','sysRole','tag')