连接数据库操作后都是成功的,但是操作结果返回null是怎么回事呢?

teddywtd 2004-12-20 02:43:20
程序都是在http://community.csdn.net/Expert/TopicView.asp?id=3660099
但是上述问题解决了,现在写数据库的时候出错哦
没有出错信息哦
就返回个null
请问是那里出了问题呢?
ConnectionPool连接数据库都是成功的
...全文
448 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
teddywtd 2004-12-20
  • 打赏
  • 举报
回复
insert into basic (Uname) values('wtd');
打印出来了,呵呵
teddywtd 2004-12-20
  • 打赏
  • 举报
回复
楼上的,在那里打啊,同样的一段程序在其他测试上都可以,在action那个文件里边就不行了,那个打在那里啊?
teddywtd 2004-12-20
  • 打赏
  • 举报
回复
为什么这里连接不上数据库呢????????在newRegAction.java中为啥连接数据库失败呢?
nouveau 2004-12-20
  • 打赏
  • 举报
回复
把System.out.println(sql) 打出来的东西直接在mysql客户端执行,看出来什么冬冬
teddywtd 2004-12-20
  • 打赏
  • 举报
回复
找到错误了,连接数据库失败
信息: Jk running ID=0 time=0/50 config=C:\tomcat4\bin\..\conf\jk2.properties
java.sql.SQLException: 数据库连接初始化失败 -> com.mysql.jdbc.Driver
at com.God.db.ConnectionPool.initialConnection(ConnectionPool.java:53)
at com.God.db.ConnectionPool.<init>(ConnectionPool.java:65)
at com.God.action.newRegAction.execute(newRegAction.java:45)
at org.apache.struts.action.RequestProcessor.processActionPerform(Reques
tProcessor.java:480)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.ja
va:274)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:142
0)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:520)
但是我在test程序中运行的时候就是可以的啊
public class test {

public static void main(String[] args){

try{
ConnectionPool pool = new ConnectionPool();
Connection con = pool.getConnection();

//String rootPath=request.getRealPath("/");
//HttpSession session = request.getSession();

char sp=java.io.File.separatorChar;
String username="wtd";//request.getParameter("username");

String sql="insert into basic (Uname) values('"+username+"');";
System.out.println(sql);
PreparedStatement stm = con.prepareStatement(sql);
stm.execute();
stm.close();
//System.out.println(username);

}

catch (Exception e) {
System.out.println(e.getMessage());
}

}

}
teddywtd 2004-12-20
  • 打赏
  • 举报
回复
我还没有把log4j加入呢,偶是新手哦
xitianjile 2004-12-20
  • 打赏
  • 举报
回复
当然是打印在日志里面最好。
但是估计楼主也不会做。。。
打印在控制台也能得到一点信息了。
zhaoqiubo 2004-12-20
  • 打赏
  • 举报
回复
在jsp页面中判断出错的位置,你可以把修改jsp页面去掉一部分代码,如果没有错误了,那么就说明错误在你去掉的代码中,如果有错误那么就说明错误在你现在的代码中,你可以通过多次去掉代码,最后找到出错的位置,这样就方便多了..如果在后面的类中出错,可以通过楼上的方法,打印出错误堆栈,但是错误堆栈要到控制台才可以看得到...其实解决问题并不是最终的目的,你要学习如何去自己解决问题!!
xitianjile 2004-12-20
  • 打赏
  • 举报
回复
newRegAction.java
public final class newRegAction extends Action{
public ActionForward execute
(ActionMapping mapping,ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception
{
Locale locale = getLocale(request);
MessageResources messages = getResources(request);
HttpSession session = request.getSession();
newRegForm regForm = (newRegForm) form;
try{
ConnectionPool pool = new ConnectionPool();
Connection con = pool.getConnection();

String username=request.getParameter("usrname");
String sql="insert into basic (Uname) values('"+username+"');";
System.out.println(sql);
PreparedStatement stm = con.prepareStatement(sql);
stm.execute();
stm.close();

return (mapping.findForward("success"));
}
catch (Exception e)
{
//加入
e.printStackTrace();
return (mapping.findForward("fail"));
}
}
}
xitianjile 2004-12-20
  • 打赏
  • 举报
回复
你用了setAttribute("Msg","message")了吗?

好像在前面的代码中没发现。
teddywtd 2004-12-20
  • 打赏
  • 举报
回复
那应该怎么弄才可以得到输出错误的地方呢?
teddywtd 2004-12-20
  • 打赏
  • 举报
回复
Info.jsp
<html>
<head>
<title>监控管理系统</title>
<%@ page contentType="text/html;charset=gb2312"%>
<%
String path = request.getContextPath();
path += "/image/xinxitishi.GIF";

%>
<!--meta http-equiv="Content-Type" content="text/html; charset=gb2312"-->
<link rel="stylesheet" href="../share/style.css" type="text/css">
</head>

<body bgcolor="#FFFFFF">
<table width="90%" border="0" height="130">
<tr>
<td height="50">
<div align="center"><img src=<%=path%> width="300" height="200"></div>
</td>
</tr>
<tr align="center">
<td align="center"> <br>
<%
String tmp = (String)request.getAttribute("Msg");

//byte[] temp_t = tmp.getBytes("ISO8859_1");
//tmp = new String(temp_t);
out.print(tmp);
%>
</td>
</tr>
</table>
</body>
</html>
xitianjile 2004-12-20
  • 打赏
  • 举报
回复
我没发现你代码里面有输出错误信息的地方。
teddywtd 2004-12-20
  • 打赏
  • 举报
回复
程序代码都在那个连接上边哦
返回的时候就到fail了.我也不知道什么错误哦
就是在info.jsp中显示null.其余什么都没有了
我用的是mysql数据库
华生豆 2004-12-20
  • 打赏
  • 举报
回复
把代码和出错信息贴出来看看~~~
xitianjile 2004-12-20
  • 打赏
  • 举报
回复
都没有输出错误。
那里来错误信息。
umljsp 2004-12-20
  • 打赏
  • 举报
回复
哪个地方返回null值,代码哪?

81,092

社区成员

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

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