当前位置: 技术问答>java相关
谁帮我解决这个问题100分送给你,在线等候!不送不是人.
来源: 互联网 发布时间:2015-09-03
本文导语: 本程序是用户注册,验证提交到数据库,按正常来说应该很容易,可是,唉,问题我是解决不了了. 说明如下: 数据库链接bean pic_dbcon 用户注册页面 freemember.jsp 验证页面 ok_freemember.jsp 写入数据库页面 end_freemember.jsp ...
本程序是用户注册,验证提交到数据库,按正常来说应该很容易,可是,唉,问题我是解决不了了.
说明如下:
数据库链接bean pic_dbcon
用户注册页面 freemember.jsp
验证页面 ok_freemember.jsp
写入数据库页面 end_freemember.jsp
程序如下:pic_dbcon
package picdb;
import java.sql.*;
public class pic_dbcon
{
//定义数据库连接!
String mysqlDriver="com.caucho.jdbc.mysql.Driver";
String mysqlURL="jdbc:mysql_caucho://localhost:3306/pic_db";
String mysqlUser="biggie";
String mysqlPassword="123";
Connection mysqlCon=null;
ResultSet rs=null;
public pic_dbcon()
{
try
{
Class.forName(mysqlDriver);
System.out.println("win");
}
catch(Exception e)
{
System.out.println("float");
e.printStackTrace();
}
}
public ResultSet executeQuery(String sql)
{
rs=null;
try
{
Class.forName(mysqlDriver);
mysqlCon= DriverManager.getConnection(this.mysqlURL,this.mysqlUser,this.mysqlPassword);
Statement stmt=mysqlCon.createStatement();
rs=stmt.executeQuery(sql);
}
catch (Exception ex)
{
System.err.println("aq.executeQuery:"+ex.getMessage());}
return rs;
}
public void executeSql(String strSQL)
{
rs=null;
try
{
Class.forName(mysqlDriver);
mysqlCon= DriverManager.getConnection(this.mysqlURL,this.mysqlUser,this.mysqlPassword);
Statement stmt=mysqlCon.createStatement();
stmt.executeUpdate(strSQL);
stmt.close();
mysqlCon.close();
}
catch (Exception ex)
{
System.err.println("aq.executeQuery:"+ex.getMessage());}
}
}
ok_freemember.jsp
免费用户注册二
end_freemember.jsp
恭喜注册成功!
祝贺你!你已经成为我们的会员了!
-------------------------------------------------------------------
出错页面ok_freemember.jsp
500 Servlet Exception
java.lang.NullPointerException
at _pic._ok_0freemember__jsp._jspService(/pic/ok_freemember.jsp:9)
at com.caucho.jsp.JavaPage.service(JavaPage.java:75)
at com.caucho.jsp.Page.subservice(Page.java:485)
at com.caucho.server.http.FilterChainPage.doFilter(FilterChainPage.java:182)
at com.caucho.server.http.Invocation.service(Invocation.java:311)
at com.caucho.server.http.CacheInvocation.service(CacheInvocation.java:135)
at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:221)
at com.caucho.server.http.HttpRequest.handleConnection(HttpRequest.java:163)
at com.caucho.server.TcpConnection.run(TcpConnection.java:137)
at java.lang.Thread.run(Thread.java:536)
--------------------------------------------------------------------------------
Resin 2.1.2 (built Tue Jun 11 08:26:56 PDT 2002)
------------------------------------------------------------------------
希望有空的朋友帮我试试,如果成功解决了我的问题,我会很感谢很感谢你们的.
一个很勇力的初学者!
说明如下:
数据库链接bean pic_dbcon
用户注册页面 freemember.jsp
验证页面 ok_freemember.jsp
写入数据库页面 end_freemember.jsp
程序如下:pic_dbcon
package picdb;
import java.sql.*;
public class pic_dbcon
{
//定义数据库连接!
String mysqlDriver="com.caucho.jdbc.mysql.Driver";
String mysqlURL="jdbc:mysql_caucho://localhost:3306/pic_db";
String mysqlUser="biggie";
String mysqlPassword="123";
Connection mysqlCon=null;
ResultSet rs=null;
public pic_dbcon()
{
try
{
Class.forName(mysqlDriver);
System.out.println("win");
}
catch(Exception e)
{
System.out.println("float");
e.printStackTrace();
}
}
public ResultSet executeQuery(String sql)
{
rs=null;
try
{
Class.forName(mysqlDriver);
mysqlCon= DriverManager.getConnection(this.mysqlURL,this.mysqlUser,this.mysqlPassword);
Statement stmt=mysqlCon.createStatement();
rs=stmt.executeQuery(sql);
}
catch (Exception ex)
{
System.err.println("aq.executeQuery:"+ex.getMessage());}
return rs;
}
public void executeSql(String strSQL)
{
rs=null;
try
{
Class.forName(mysqlDriver);
mysqlCon= DriverManager.getConnection(this.mysqlURL,this.mysqlUser,this.mysqlPassword);
Statement stmt=mysqlCon.createStatement();
stmt.executeUpdate(strSQL);
stmt.close();
mysqlCon.close();
}
catch (Exception ex)
{
System.err.println("aq.executeQuery:"+ex.getMessage());}
}
}
ok_freemember.jsp
免费用户注册二
你的用户注册信息如下:
用户名:
密 码:
E_MAIL:
end_freemember.jsp
恭喜注册成功!
祝贺你!你已经成为我们的会员了!
-------------------------------------------------------------------
出错页面ok_freemember.jsp
500 Servlet Exception
java.lang.NullPointerException
at _pic._ok_0freemember__jsp._jspService(/pic/ok_freemember.jsp:9)
at com.caucho.jsp.JavaPage.service(JavaPage.java:75)
at com.caucho.jsp.Page.subservice(Page.java:485)
at com.caucho.server.http.FilterChainPage.doFilter(FilterChainPage.java:182)
at com.caucho.server.http.Invocation.service(Invocation.java:311)
at com.caucho.server.http.CacheInvocation.service(CacheInvocation.java:135)
at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:221)
at com.caucho.server.http.HttpRequest.handleConnection(HttpRequest.java:163)
at com.caucho.server.TcpConnection.run(TcpConnection.java:137)
at java.lang.Thread.run(Thread.java:536)
--------------------------------------------------------------------------------
Resin 2.1.2 (built Tue Jun 11 08:26:56 PDT 2002)
------------------------------------------------------------------------
希望有空的朋友帮我试试,如果成功解决了我的问题,我会很感谢很感谢你们的.
一个很勇力的初学者!
|
把这个方法加到你的bean里面。
public String NullToSp(String Col) {
if (Col == null)
return "";
else
return Col.trim();
}
String username=pic_dbcon.NullToSprequest.getParameter("username"));
就可以避免username为null了。
还有,数据库连接在使用后必须关闭,你的就没有关闭,我帮你改了,你看看我上面给你帖的程序吧
public String NullToSp(String Col) {
if (Col == null)
return "";
else
return Col.trim();
}
String username=pic_dbcon.NullToSprequest.getParameter("username"));
就可以避免username为null了。
还有,数据库连接在使用后必须关闭,你的就没有关闭,我帮你改了,你看看我上面给你帖的程序吧
|
public boolean executeQuery(String sql)
{
rs=null;
boolean flag=false;
try
{
Class.forName(mysqlDriver);
mysqlCon= DriverManager.getConnection(this.mysqlURL,this.mysqlUser,this.mysqlPassword);
Statement stmt=mysqlCon.createStatement();
rs=stmt.executeQuery(sql);
if (rs.next())
{
flag=true;
}
rs.close();
stmt.close();
}
catch (Exception ex)
{
System.err.println("aq.executeQuery:"+ex.getMessage());
}finally {
mysqlCon.close(); // 关闭数据库
}
return flag;
}
免费用户注册二
你试试吧
{
rs=null;
boolean flag=false;
try
{
Class.forName(mysqlDriver);
mysqlCon= DriverManager.getConnection(this.mysqlURL,this.mysqlUser,this.mysqlPassword);
Statement stmt=mysqlCon.createStatement();
rs=stmt.executeQuery(sql);
if (rs.next())
{
flag=true;
}
rs.close();
stmt.close();
}
catch (Exception ex)
{
System.err.println("aq.executeQuery:"+ex.getMessage());
}finally {
mysqlCon.close(); // 关闭数据库
}
return flag;
}
免费用户注册二
你的用户注册信息如下:
用户名:
密 码:
E_MAIL:
你试试吧