问题描述
我是刚学jsp,没学多久就遇到了问题,之前在网上查了好多办法,都没有弄好,求求哪位好心人帮帮我exceptionorg.apache.jasper.JasperException:AnexceptionoccurredprocessingJSPpage/sql_1.jspatline1512:Stringurl="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=student";13:Stringuser="sa";14:Stringpassword="sa";15:Connectioncon=DriverManager.getConnection(url,user,password);16:Statementstmt=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);17:Stringsql="select*fromt_sno";18:ResultSetrs=stmt.executeQuery(sql);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)rootcausejavax.servlet.ServletException:java.sql.SQLException:[Microsoft][SQLServer2000DriverforJDBC]Errorestablishingsocket.org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:855)org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:784)org.apache.jsp.sql_005f1_jsp._jspService(sql_005f1_jsp.java:98)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)rootcausejava.sql.SQLException:[Microsoft][SQLServer2000DriverforJDBC]Errorestablishingsocket.com.microsoft.jdbc.base.BaseExceptions.createException(UnknownSource)com.microsoft.jdbc.base.BaseExceptions.getException(UnknownSource)com.microsoft.jdbc.base.BaseExceptions.getException(UnknownSource)com.microsoft.jdbc.sqlserver.tds.TDSConnection.<init>(UnknownSource)com.microsoft.jdbc.sqlserver.SQLServerImplConnection.open(UnknownSource)com.microsoft.jdbc.base.BaseConnection.getNewImplConnection(UnknownSource)com.microsoft.jdbc.base.BaseConnection.open(UnknownSource)com.microsoft.jdbc.base.BaseDriver.connect(UnknownSource)java.sql.DriverManager.getConnection(UnknownSource)java.sql.DriverManager.getConnection(UnknownSource)org.apache.jsp.sql_005f1_jsp._jspService(sql_005f1_jsp.java:68)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)noteThefullstacktraceoftherootcauseisavailableintheApacheTomcat/6.0.10logs.
解决方案
解决方案二:
Connectioncon=DriverManager.getConnection(url,user,password);这里会出现异常,你没有处理。Connectioncon=null;Statementstmt=null;ResultSetrs=null;try{con=DriverManager.getConnection(url,user,password);stmt=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);Stringsql="select*fromt_sno";ResultSetrs=stmt.executeQuery(sql);}catch(Exceptione){}
解决方案三:
Stringurl="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=student";这句话出错了,改写成Stringurl="jdbc:microsoft:sqlserver://localhost:1433/student";就ok了1433是不是你的端口号呀。很多人都是3306
解决方案四:
我咋没看见加载JDBC驱动啊
解决方案五:
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");Connectioncon=DriverManager.getConnection(url,user,password);
解决方案六:
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");Connectioncon=DriverManager.getConnection(url,user,password);
解决方案七:
汗,楼主貌似没有加载驱动吧……后面java.sql.SQLException:[Microsoft][SQLServer2000DriverforJDBC]Errorestablishingsocket也说了驱动引起的,先加载驱动Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");然后再做下一步操作啊……Connectioncon=DriverManager.getConnection(url,user,password);
解决方案八:
以前连接成功过吗?会不会是驱动版本问题
解决方案九:
估摸着你的驱动程序没有放进来
解决方案十:
引用2楼m690192206的回复:
Stringurl="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=student";这句话出错了,改写成Stringurl="jdbc:microsoft:sqlserver://localhost:1433/student";就ok了1433是不是你的端口号呀。很多人都是3306
sqlserver的url就是这么写的,默认端口号是1433。3306是mysql的默认端口号。楼主忘了加载jar包了,应该是!sqlserver共有3个jar包:msbase.jar、mssqlserver.jar、msutil.jar并且以这种方式实现的话,xp用户需要打SP3的补丁另附,以前整理的SqlServer的jdbc实现方式。第一种:JDBC-ODBC数据库连接桥(需要配置ODBC数据源,不需下载驱动)Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");con=DriverManager.getConnection("jdbc:odbc:数据源名称","用户名","密码");第二种:利用Microsoft提供的驱动程序(XP用户需要打SP3的补丁,需要下载驱动)Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");con=DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433;databasename=数据库名","用户名","密码");第三种:利用第三方提供的驱动程序(需要下载驱动)Class.forName("net.sourceforge.jtds.jdbc.Driver");con=DriverManager.getConnection("jdbc:jtds:sqlserver://localhost:1433/数据库名;user=用户名;password=密码");第四种:在Struts下配置数据源(其实这种方式跟上边的不属于一种类型)<data-sources><data-sourcekey="在Struts中数据源的名称"type="org.apache.commons.dbcp.BasicDataSource"><set-propertyproperty="driverClassName"value="sun.jdbc.odbc.JdbcOdbcDriver"/><set-propertyproperty="url"value="jdbc:odbc:数据源"/><set-propertyproperty="username"value="用户名"/><set-propertyproperty="password"value="密码"/></data-source></data-sources>额,我没仔细看报的什么错,总之就先贴上来了,我学校马上要断网了,~~~~(>_<)~~~~
解决方案十一:
[Microsoft][SQLServer2000DriverforJDBC]Errorestablishingsocket.
异常已经说的很清楚了,,不能启用端口号,你用命令查看一下1433端口开了没有!!
解决方案十二:
引用2楼m690192206的回复:
Stringurl="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=student";这句话出错了,改写成Stringurl="jdbc:microsoft:sqlserver://localhost:1433/student";就ok了1433是不是你的端口号呀。很多人都是3306
大哥,这是MSqlserver,不是mysql
解决方案十三:
引用5楼voice1122的回复:
JavacodeClass.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");Connectioncon=DriverManager.getConnection(url,user,password);
+1
解决方案十四:
1433是不是你的端口号??