Topic: 为什么怎么简单的数据库连接都有错呢????? |
Print this page |
1.为什么怎么简单的数据库连接都有错呢????? | Copy to clipboard |
Posted by: voit25 Posted on: 2006-04-28 14:38 <%@ page contentType="text/html; charset=GBK" %> <%@page import="java.sql.*"%> <html> <% String url="jdbc:odbc:zms"; Connection conn=null; String s=null; try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance(); conn=DriverManager.getConnection(url,"",""); } catch(java.lang.Exception ex){ex.printStackTrace();} if(conn.equals(null)){s="不对!";}else{s="可以的!";} %> <%=s %> </html> 错误是::: Exception report message description The server encountered an internal error () that prevented it from fulfilling this request. exception org.apache.jasper.JasperException org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:372) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236) javax.servlet.http.HttpServlet.service(HttpServlet.java:802) root cause java.lang.NullPointerException org.apache.jsp.co_jsp._jspService(co_jsp.java:60) org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94) javax.servlet.http.HttpServlet.service(HttpServlet.java:802) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236) javax.servlet.http.HttpServlet.service(HttpServlet.java:802) note The full stack trace of the root cause is available in the Apache Tomcat/5.0.29 logs. |
2.Re:为什么怎么简单的数据库连接都有错呢????? [Re: voit25] | Copy to clipboard |
Posted by: 毒毒√快山 Posted on: 2006-04-28 14:48 try { Class.forName("org.gjt.mm.mysql.Driver").newInstance(); Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/AJiaSi","root",""); return con; } catch (SQLException ex) { ex.printStackTrace(); return null; } 这是我自己的,你招这个写,在试试哦 |
3.Re:为什么怎么简单的数据库连接都有错呢????? [Re: voit25] | Copy to clipboard |
Posted by: YuLimin Posted on: 2006-05-02 10:39
jdbcodbc为我建立的ODBC源,没有问题的,把你的LOG放上来看看是什么问题 从程序及出错的信息java.lang.NullPointerException上面来看,问题应当出在: if(conn.equals(null)){s="不对!";}else{s="可以的!";} 应当写为 if(conn == null){s="不对!";}else{s="可以的!";} 也就是说你的Connection没有得到为null而在此语句上面导致NullPointerException错误的。 看你的ex.printStackTrace();打印出的详细错误是什么,放上来。 |
4.Re:为什么怎么简单的数据库连接都有错呢????? [Re: voit25] | Copy to clipboard |
Posted by: voit25 Posted on: 2006-05-03 10:17 谢谢! 搞出来了! 再一次谢谢! |
Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1 客服电话 18559299278 客服信箱 714923@qq.com 客服QQ 714923 |