空指针问题???急

xtuyaowu 2005-04-08 12:54:48
空指针 但是为什么 我把我的.jsp and bean paste 出来了帮我看看,谢谢了
java.lang.NullPointerException
myfirstbean.DataOperate.insertSQLCommand(DataOperate.java:96)
org.apache.jsp.register_jsp._jspService(register_jsp.java:87)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)

rigister.jsp

<html>
<body>
<%@page language="java"%>
<form method="post" action="insertNews.jsp" enctype="multipart/form-data">
<%@ page import="java.lang.*"%>
<jsp:useBean id="dataOperate" class="myfirstbean.DataOperate"/>
<%
dataOperate.openConnection();

String name,Anonymous,email,descrip,num,cod;
int code,telnumber;


cod=request.getParameter("co");
num=request.getParameter("telnumb");
name=request.getParameter("na");
Anonymous=request.getParameter("Anonymo");
descrip=request.getParameter("descr");
code=Integer.parseInt(cod);
telnumber=Integer.parseInt(num);
email=request.getParameter("ema");

System.out.println(name);
System.out.println(Anonymous);


dataOperate.setName(name);dataOperate.setAnonymous(Anonymous);dataOperate.setCode(code);
dataOperate.setEmail(email);dataOperate.setTel(telnumber);dataOperate.setDescription(descrip);

String inSertCommand="insert into Customer Values('"+dataOperate.getName()+"','"+dataOperate.getAnonymous()+"',"+dataOperate.getCode()+",'"+dataOperate.getEmail()+"',"+dataOperate.getNumber()+",'"+dataOperate.getDescription()+"')";

String execut="inSertCommand ";
dataOperate.insertSQLCommand(execut );


%>
<%out.print("注册成功,恭喜你");%>

</form>
</body>
</html>


package myfirstbean;
import java.sql.*;
public class DataOperate{

Connection theConnection;
Statement theStatement;
ResultSet theResult;

String theDataSource,theUser,thePassword,theName,theAnonymous,
theEmail,description,insertCommand;

int telNumb,theCode;

//设置和获得参数
public void setName(String name){

theName=name;
}
public String getName(){

return theName;

}

public void setAnonymous(String Anonymous){

theAnonymous=Anonymous;
}
public String getAnonymous(){

return theAnonymous;
}

public void setCode(int code){

theCode=code;
}

public int getCode(){

return theCode;

}

public void setEmail(String email){
theEmail=email;
}
public String getEmail(){
return theEmail;
}

public void setTel(int telnumber){
telNumb= telnumber;
}
public int getNumber(){

return telNumb;
}

public void setDescription(String descrip){

description=descrip;

}

public String getDescription(){

return description;

}

static void openConnection(){

theDataSource= "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=mydata";
theUser="sa";
thePassword=" ";

try{

Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
theConnection=DriverManager.getConnection(theDataSource,theUser,thePassword);
theStatement=theConnection.createStatement();

}catch(Exception e){
e.printStackTrace();
System.out.println("Error Trace in getConnection() : " + e.getMessage());
}

}

static void insertSQLCommand(String inSertCommand){

try{

theResult=theStatement.executeQuery(inSertCommand);
}catch(SQLException e){ e.printStackTrace();
System.out.println("Error Trace in executeQuery() : " + e.getMessage());
}


}



}
...全文
97 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
xtuyaowu 2005-04-09
  • 打赏
  • 举报
回复
问题出在: 但调不好 我不用bean 完全 能够解决 但是 如果加如大量代码的话 不太科学!!!
dataOperate.insertSQLCommand(execut );
galewithwing 2005-04-08
  • 打赏
  • 举报
回复
应该是你的某个对象或者参数为空,引用的时候就出错了,
你在程序中加一些调试信息就可以定位了
bitou 2005-04-08
  • 打赏
  • 举报
回复
String execut="inSertCommand ";
dataOperate.insertSQLCommand(execut );

效果是这样:
dataOperate.insertSQLCommand("inSertCommand ");//这不是你所期望的

另外,你把这句
dataOperate.openConnection();
放在了最前面,而直到最后才引用到它,这个习惯不太好
kigoqzw 2005-04-08
  • 打赏
  • 举报
回复
String execut="inSertCommand ";
莫名
fashchina 2005-04-08
  • 打赏
  • 举报
回复
String execut="inSertCommand ";
dataOperate.insertSQLCommand(execut );

这个什么意思
就直接用
dataOperate.insertSQLCommand(inSertCommand);
确保sql没错,和值都传对

真不明白你什么意思

来个这个:String execut="inSertCommand ";

81,094

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧