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

sql+tomcat的有关问题,十多天解决不了

2013-09-11 
sql+tomcat的问题,十多天解决不了,救命啊源程序%@pagecontentType text/htmlcharsetGB2312 %%@pag

sql+tomcat的问题,十多天解决不了,救命啊
源程序
<%@   page   contentType= "text/html;charset=GB2312 "   %>
<%@   page   import= "java.sql.* "   %>
<html>
<body>
<%
  Connection   con;
  Statement   sql;
  ResultSet   rs;
        out.print( "a ");
        con=DriverManager.getConnection( "jdbc:odbc:yuan ", "sa ", " ");
            out.print( "b ");
        sql=con.createStatement();
        rs=sql.executeQuery( "SELECT   *   FROM   login ");
        while(rs.next())
{
        out.print(rs.getString( "name "));
        out.print(rs.getString( "password "));
}
con.close();
%>    
</body>
</html>    
错误
exception  

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

7:     Statement   sql;
8:     ResultSet   rs;
9:           out.print( "a ");
10:           con=DriverManager.getConnection( "jdbc:odbc:yuan ", "sa ", " ");
11:               out.print( "b ");
12:           sql=con.createStatement();
13:           rs=sql.executeQuery( "SELECT   *   FROM   login ");


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:   No   suitable   driver
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:855)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:784)
org.apache.jsp.tt_jsp._jspService(tt_jsp.java:82)
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:   No   suitable   driver
java.sql.DriverManager.getConnection(DriverManager.java:545)
java.sql.DriverManager.getConnection(DriverManager.java:171)
org.apache.jsp.tt_jsp._jspService(tt_jsp.java:63)
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
谢谢好心人

[解决办法]
不是要先加载 sql驱动程序吗?
Class.forName();
[解决办法]
你的代码是用普通文本编辑器写的吧,你用集成环境重新写一下这段代码再试一下。
[解决办法]
好象连接数据库的IP 都没写?
[解决办法]
没的加载驱动,Class.forName( ".......... ").


[解决办法]
还有这个con=DriverManager.getConnection( "jdbc:odbc:yuan ", "sa ", " ");
jdbc:odbc:yuan这个怎么来的
[解决办法]
先加载驱动
Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver ");
然后
con=DriverManager.getConnection( "jdbc:odbc:yuan ", "sa ", " ");
你用的是jdbc.odbc桥连接
你可以用直连的方式

String driver= "com.microsoft.jdbc.sqlserver.SQLServerDriver ";
String url= "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=test ";
try{
Class.forName(driver)
con=DriverManager.getConnection(url, "sa ", " ");
}catch(Exception e){

}
这是用sql server2000数据库
还有要注意用try catch块
[解决办法]
这个问题好玩。java.sql.SQLException: No suitable driver是关键
[解决办法]
Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver ");正解
我的异常网推荐解决方案:An exception occurred processing JSP page,http://www.myexception.cn/j2se/33144.html

热点排行