struts1中dynaactionform和Dao的问题

tingxinxinshuo 2011-06-19 12:47:00
麻烦各位大哥给看看 我要实现的功能很简单 就是个登陆 可是到了DAO那地方 总是空指针
这是DAO文件
public class Dao {
Connection conn;
public Connection getConn() throws SQLException{
DriverManager.registerDriver(new OracleDriver());
String url="jdbc:oracle:thin:@localhost:1521:ORCL";
DriverManager.getConnection(url,"scott","tiger");
return conn;
}
public boolean Login(DynaActionForm showForm) throws SQLException{
conn=this.getConn();
PreparedStatement pstmt;
pstmt=conn.prepareStatement("select * from LX where ID=? and NAME=?");总显示这有问题
pstmt.setInt(1, Integer.parseInt( (String) showForm.get("ID")));
pstmt.setString(2, (String)showForm.get("NAME"));
ResultSet rs=pstmt.executeQuery();
if(rs.next()){
rs.close();
pstmt.close();
conn.close();
return true;
}
else{
rs.close();
pstmt.close();
conn.close();
return false;
}
}

}
这是Action文件
public ActionForward Login(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws SQLException {
DynaActionForm showForm = (DynaActionForm) form;// TODO Auto-generated method stub
Dao dao=new Dao();




if(dao.Login(showForm)){
return mapping.findForward("my");
}
else{
return mapping.findForward("you");
}

}
...全文
40 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
JavaMan_KA 2011-06-20
  • 打赏
  • 举报
回复
public Connection getConn() throws SQLException{
DriverManager.registerDriver(new OracleDriver());
String url="jdbc:oracle:thin:@localhost:1521:ORCL";
DriverManager.getConnection(url,"scott","tiger");
return conn;
}
在你的getConn()方法中没有给conn赋值的地方,返回当然还是null,要注意细节。
yanweijie0317 2011-06-20
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 javaman_ka 的回复:]

public Connection getConn() throws SQLException{
DriverManager.registerDriver(new OracleDriver());
String url="jdbc:oracle:thin:@localhost:1521:ORCL";
DriverManager.getConnection(url,"scott","tig……
[/Quote]
tingxinxinshuo 2011-06-19
  • 打赏
  • 举报
回复
没个大大愿意帮下吗
tingxinxinshuo 2011-06-19
  • 打赏
  • 举报
回复
其实吧问题精简一下就是如何把页面受到的数据封装到showForm里

81,091

社区成员

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

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