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

高分求简单有关问题(数据库访问)

2013-09-11 
高分求简单问题(数据库访问)JDBC数据库连接问题,提示说数据源(access)不正确,我已经在ODBC数据源中,配置好

高分求简单问题(数据库访问)
JDBC数据库连接问题,提示说数据源(access)不正确,我已经在ODBC数据源中,配置好了,可一运行到这里就出错,请大侠们帮解决呀,星期五就要交啦!


错误提示是这些:
type   Exception   report

message  

description   The   server   encountered   an   internal   error   ()   that   prevented   it   from   fulfilling   this   request.

exception  

org.apache.jasper.JasperException:   An   exception   occurred   processing   JSP   page   /newslist.jsp   at   line   23

20:   %>
21:   <%
22:         Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver ");  
23:         odbcconn   =   DriverManager.getConnection( "jdbc:odbc:mydata ");  
24:         odbcstmt   =   odbcconn.createStatement();  
25:         odbcQuery= "Select   *   From   sys_news   order   by   news_id   DESC ";  
26:         odbcrs=odbcstmt.executeQuery(odbcQuery);  


Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:515)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:408)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)


root   cause  

javax.servlet.ServletException:   java.sql.SQLException:   General   error
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:855)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:784)
org.apache.jsp.newslist_jsp._jspService(newslist_jsp.java:183)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:384)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)


root   cause  

java.sql.SQLException:   General   error
sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6987)
sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7115)
sun.jdbc.odbc.JdbcOdbc.SQLDriverConnect(JdbcOdbc.java:3074)
sun.jdbc.odbc.JdbcOdbcConnection.initialize(JdbcOdbcConnection.java:323)
sun.jdbc.odbc.JdbcOdbcDriver.connect(JdbcOdbcDriver.java:174)
java.sql.DriverManager.getConnection(DriverManager.java:525)
java.sql.DriverManager.getConnection(DriverManager.java:193)
org.apache.jsp.newslist_jsp._jspService(newslist_jsp.java:140)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:384)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)


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


--------------------------------------------

Apache   Tomcat/6.0.10




源程序是这样的
<%@   include   file= "function/lang.jsp "   %>
<%@   page   import= "java.sql.* "%>
<%@   include   file= "function/navigate.jsp "   %>
<%@   include   file= "function/header.jsp "   %>
<%   out.println(ShowNavigate( "news "));%>


<table   width= "784 ">
<%@page   import   = "java.util.* "  
import   = "java.io.* "  
import= "java.text.* "  
buffer= "20kb "  
%>
<%!   int   all,i,m_count;  
String   odbcQuery;  
Connection   odbcconn;  
Statement   odbcstmt;  
ResultSet   odbcrs;  
ResultSetMetaData   mymetadata;  
%>
<%
      Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver ");  
      odbcconn   =   DriverManager.getConnection( "jdbc:odbc:mydata ");  
      odbcstmt   =   odbcconn.createStatement();  
      odbcQuery= "Select   *   From   sys_news   order   by   news_id   DESC ";  
      odbcrs=odbcstmt.executeQuery(odbcQuery);  
      mymetadata=odbcrs.getMetaData();
      int   columncount=mymetadata.getColumnCount();  
while   (odbcrs.next())  
{  
          int   i;  
        out.print( " <tr> ");
        for   (i=1;i <=columncount;i++)   out.print( " <td> Cloumn   "+i+ "   is:   "+odbcrs.getString(i)+ " </td> ");  
        out.print( " </tr> ");
}


odbcrs.close();  
odbcstmt.close();  
odbcconn.close();  
%>    
</table>

<%@   include   file= "function/footer.jsp "   %>

[解决办法]
TO: Rachael1001(野谷子)
ODBC(数据源) 如果他建数据源的时候没设置用户名和密码, 那么连接字符里是不需要写的,而且也不需要写数据库名, 因为那是配置在ODBC里的,程序里写数据源名就可以了
[解决办法]
用access数据库连接ODBC应当是这样写的:
Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver ") ;
String url= "jdbc:odbc:Driver={MicroSoft Access Driver (*.mdb)};DBQ= "+application.getRealPath( "/数据库名.mdb ");
Connection conn = DriverManager.getConnection(url, " ", " ");
Statement stmtNew=conn.createStatement() ;

lz你好像写错了!
[解决办法]
用Access数据库连接ODBC应当是这样写的:
Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver ") ;
String url= "jdbc:odbc:Driver={MicroSoft Access Driver (*.mdb)};DBQ= "+application.getRealPath( "/数据库名.mdb ");
Connection conn = DriverManager.getConnection(url, " ", " ");
Statement stmtNew=conn.createStatement() ;

楼上说得对
lz你好像写错了!
[解决办法]
JDBC_ODBC连接Access数据库,不需要设置数据源

我的异常网推荐解决方案:An exception occurred processing JSP page,http://www.myexception.cn/j2se/33144.html
我的异常网推荐解决方案:The server encountered an internal error () that prevented it from fulfilling this request.,http://www.myexception.cn/java-web/317.html

热点排行