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

连接sql的有关问题

2013-09-11 
连接sql的问题%@pagecontentType text/htmlcharsetgb2312 %%@pageimport java.sql.* %省略中

连接sql的问题
<%@   page   contentType= "text/html;charset=gb2312 "%>
<%@   page   import= "java.sql.* "%>

<省略中间自动生成代码>


body内的代码
<%try{Class.forName( "com.microsft.jdbc.sqlserver.SQLServerDriver ").newInstance();}catch(Exception   ex){out.print( "       aa         ");}   %>
        <%Connection   con   =   DriverManager.getConnection( "jdbc:microsoft:sqlserver://localhost:1433 ",   "sa ",   " ");   %>


==================================
==================================
==================================
报的这个错


HTTP   Status   500   -  

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

type   Exception   report

message  

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

exception  

javax.servlet.ServletException:   No   suitable   driver
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:848)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:781)
org.apache.jsp.src.MyJsp_jsp._jspService(org.apache.jsp.src.MyJsp_jsp:95)
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:322)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:291)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


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.src.MyJsp_jsp._jspService(org.apache.jsp.src.MyJsp_jsp: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:322)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:291)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
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.9   logs.


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

Apache   Tomcat/5.5.9


========
这个是怎么回事啊?           project的属性中已经引入了sql   jdbc的3个jar文件了

[解决办法]
楼主搞错了,试试这个吧,
<%
try
{
Class.forName( "com.microsoft.jdbc.sqlserver.SQLServerDriver ").newInstance();
String url= "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=hengan;useUnicode=true&characterEncoding=GBK ";
//pubs为你的数据库的
String user= "sa ";
String password= "1234 ";
Connection con=DriverManager.getConnection(url,user,password);


Statement stmt=con.createStatement();
String querystring= "insert into tp_jtq() values() " ;

stmt.executeUpdate(querystring);
stmt.close();
con.close();

}
catch(Exception e)
{
System.err.println( " 数据插入不成功! "+e.getMessage());
}
%>
[解决办法]
No suitable driver;
没有合适的驱动
把ms的驱动放到WEB-INF\lib下
[解决办法]
同意楼上的说法
[解决办法]
jdbc:microsoft:sqlserver://localhost:1433
没指明连接的数据库
我的异常网推荐解决方案:The server encountered an internal error () that prevented it from fulfilling this request.,http://www.myexception.cn/java-web/317.html

热点排行