首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

空指针有关问题`高手快来`

2011-12-30 
空指针问题``高手快来``这个程序那里有问题吗?%@pagecontentType text/htmlcharsetgb2312 %%@page

空指针问题``高手快来``
这个程序那里有问题吗?

<%@   page   contentType= "text/html;charset=gb2312 "%>
<%@   page   import= "java.sql.* "%>
<%@   page   import= "javax.sql.* "%>
<%@   page   import= "javax.naming.* "%>
<html>
<head> <title> jsp登录页面 </title> </head>
<body>
<center>
<%
        request.setCharacterEncoding( "gb2312 ");
        String   name=request.getParameter( "name ");
String   password=request.getParameter( "password ");
Connection   conn=null;
Statement   stmt=null;
PreparedStatement   pstmt=null;
ResultSet   rs=null;
String   sql=null;
%>

<%
                sql= "   select   *   from   zhuce   where   name=? ";
Context   ctx   =new   InitialContext();
DataSource   ds=(DataSource)ctx.lookup( "java:comp/env/jdbc/luntan ");
conn=ds.getConnection();
                rs=stmt.executeQuery(sql);
if(!rs.next())
                {
    try{
    pstmt=conn.prepareStatement( "insert   into   zhuce(name,password)values(?,?) ");  
    pstmt.setString(1,name);
    pstmt.setString(2,password);
    pstmt.executeQuery();
    out.println(name);
    out.println(password);
    }
    catch(Exception   e)
    {e.printStackTrace();}
%>
                          <jsp:forward   page= "success.jsp "/>
<%
        rs.close();
pstmt.close();
                conn.close();
}
else
{
%>
              <jspj:forward   page= "failure.jsp "/>
<%
        }
%>

</center>
</body>
</html>


<%@   page   contentType= "text/html;charset=gb2312 "%>
<html>
<head>
<title> 注册页面 </title>
</head>
<body>
<center>
<h1> 注册页面 </h1> <br>
<hr>
<br>
<br>
<br>
<form   action= "judge.jsp "   method= "post ">
<table>
<tr>
<td> 用户名: </td>
<td> <input   type= "text "   name= "name "/> </td>
</tr>
<tr>
<td> 密&nbsp;&nbsp码 </td>
<td> <input   type= "password "   name= "password "/> </td>
</tr>

<tr>
<td> <input   type= "submit "   value= "注册 "/> </td>
<td> <input   type= "reset "   value= "重置 "/> </td>
</tr>
</table>
</form>
<center>
</body>
</html>

------解决方案--------------------


sql= " select * from zhuce where name=? ";
rs=stmt.executeQuery(sql);

用pstmt阿 你的sql里面有? 需要pstmt.setString();


MVC吧 大哥 眼快瞎了
[解决办法]
你把错误贴出来呀!...
[解决办法]
conn=ds.getConnection();
rs=stmt.executeQuery(sql);
这里错误;而且你用的是带参数的sql语句,应该使用PreparedStatement类阿
PreparedStatement pstmt = null;


conn=ds.getConnection();
pstmt = conn.prepareStatement( sql);
rs = pstmt.executeQuery();
[解决办法]
2楼已经指的很清楚

热点排行