MyException - 我的异常网
当前位置:我的异常网» Eclipse » 新手提问;连接数据库如何就那么难?帮小弟我看看这

新手提问;连接数据库如何就那么难?帮小弟我看看这个有关问题(2)

www.MyException.Cn,网友分享于:2013-01-01   浏览:12次

<link   rel= "stylesheet "   type= "text/css "   href= "styles.css ">
-->

    </head>
    <body>
    <%
    DBConn   dbConn=new   DBConn();
    String   sql= "select   *   from   myorder ";
    try
    {
    PreparedStatement   ps=dbConn.getPreparedStatement(sql);
    ResultSet   rs=ps.executeQuery();
    while(rs.next())
    {
    out.println(rs.getString(0));
    }
    }
    catch(SQLException   e)
    {
    e.printStackTrace();
    }
    %>
    </body>
</html>
-----------------------------------------------
错误信息:

org.apache.jasper.JasperException:   Exception   in   JSP:   /testDBConn.jsp:34

31:       try
32:       {
33:       PreparedStatement   ps=dbConn.getPreparedStatement(sql);
34:       ResultSet   rs=ps.executeQuery();
35:       while(rs.next())
36:       {
37:       out.println(rs.getString(0));


Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:506)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:395)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


root   cause  

java.lang.NullPointerException
org.apache.jsp.testDBConn_jsp._jspService(testDBConn_jsp.java:83)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:334)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


note   The   full   stack   trace   of   the   root   cause   is   available   in   the   Apache   Tomcat/5.5.20   logs.

求助!!!!!!!!!!!!!!!!!!!!!!!!!!!!1


------解决方案--------------------
1,检查你的数据库的名称是否一致
2,测测你的SQL Server的服务端口(1433)打开没有
------解决方案--------------------

应该是这样把

try
{
Class.forName(Driver).newInstance();
}
catch(ClassNotFoundException e)
{
e.printStackTrace();
return null
}
相关解决方案
  • 暂无相关解决方案
软件开发程序错误异常ExceptionCopyright © 2009-2014MyException 版权所有