在jsp中用jdbc连接mysql数据库数据库总是报错sqlexception connection是不可用的类型

TOMCAT应用无法连接到SQL SERVER2005数据库
我的图书馆
TOMCAT应用无法连接到SQL SERVER2005数据库
问题: &&&&&& 新装一台服务器,布署TOMCAT应用后无法访问另一台SQL SERVER2005数据库。数据库可以被其它计算机访问,防火墙也未开启。驱动程序很可以正常工作。错误发生在:Connection conn=DriverManager.getConnection(url,user,pwd); 这条语句,但用户名、密码、URL均正确,同样的语句放到其它计算机上可正常执行。
错误提示如下:&
type Exception report
description The server encountered an internal error () that prevented it from fulfilling this request.
exception org.apache.jasper.JasperException: javax.servlet.ServletException: com.microsoft.sqlserver.jdbc.SQLServerException: agent.server: agent.server
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:502)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:412)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
root cause javax.servlet.ServletException: com.microsoft.sqlserver.jdbc.SQLServerException: agent.server: agent.server
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:865)
在/etc/hosts文件中加入:192.168.x.x agent agent.server分析:
应该是数据库的认证造成的。虽然我们用的是IP访问数据库服务器,但可能数据库服务器对TOMCAT进行了认证,它无法确定agent.server的IP地址,最终导致超时。
TA的最新馆藏
喜欢该文的人也喜欢JSP连接SQL server2005数据库出现这样的情况:java.sql.SQLException: No suitable driver found for jdbc_百度知道
JSP连接SQL server2005数据库出现这样的情况:java.sql.SQLException: No suitable driver found for jdbc
求高手点拨
代码是:&%@ page contentType=&text/charset=gb2312&%&
&%@ page import=&java.sql.*&%&
Class.forName(&com.microsoft.sqlserver.jdbc.SQLServerDriver&);
String url=&jdbc:microsoft:sql...
我有更好的答案
&SELECT * FROM user where user='&+user+&' &#47,我曾经也谢过类似的代码;)); C Statement sql:wzxw&user&quot.JdbcOdbcDriver&%}&,&&;utf-8&);} catch(Exception e){} }%&&% String user=transch(request.getParameter(&quot你这个应该是加载驱动的时候出错了;jdbc:'&); if(yonghupage.jsp&/&&%}else {%&gt.setAttribute(&user&;&&lt.getConnection(&quot,链接数据库的时候没有合适的J and password='&+pwd+&
sql=con.createStatement();
rs=sql.executeQuery(&&&}catch(SQLException el){}%&gt:forward page=&yhdel.jsp&).jdbc.
try{Class.forName(&quot.close(); String pwd=transch(request,user);).getBytes(&iso-8859-1&); str=new String(lb,发一份给你看看吧!&body&&%! public String transch(String str){ try{ byte[] lb=str.next()){%&&jsp:forward page=&));
catch(ClassNotFoundException e){}
con=DriverManager,&quot.getParameter(&pwd&quot
采纳率:37%
jdbc:.0:/&#47String url=&quot:1433;DatabaseName=college&;DatabaseName=college&quot.l;;
换成String url=&/127.0.0.l:;jdbc:microsoft:sqlserver:&#47:sqlserver
先检查一下,你的jdbc名称有没有写错,再检查jdbc驱动是否放入了项目的classpath中。
语句都没错,再仔细检查一下,或者是不是忘记把连接数据库的jar包copy进来
引用的jdbc驱动有问题,根据你自己的数据库版本下载jdbc驱动并加载就可以了。
使用的驱动不一样吧,检查你的连接串,看看什么错误
其他4条回答
为您推荐:
其他类似问题
换一换
回答问题,赢新手礼包
个人、企业类
违法有害信息,请在下方选择后提交
色情、暴力
我们会通过消息、邮箱等方式尽快将举报结果通知您。运行index.jsp出现这样的报错java.sql.SQLException: No value specified for parameter 1
运行index.jsp出现这样的报错java.sql.SQLException: No value specified for parameter 1然后只出现商品展示四个字 什么内容也木有了 我的代码是 &h1&
&B&商品展示&B& &/h1& &hr& &center&
&table width="750" height="60" cellpadding="0" cellspacing="0"
border="0"&
&!-- 商品循环开始 --&
ItemsDAO itemsDao = new ItemsDAO();
ArrayList&Items& list = itemsDao.getAllItems();
if (list != null && list.size() & 0) {
for (int i = 0; i & list.size(); i++) {
Items item = list.get(i);
&a href="details.jsp?id=&%=item.getId()%&"&&img
src="images/&%=item.getPicture()%&" width="120" height="90"
border="1" /&&/a&
&dd class="dd_name"&&%=item.getName()%&&/dd&
&dd class="dd_press"&出版社:&%=item.getPress()%&&/dd&
&dd class="dd_price"&价格:¥&%=item.getPrice()%&&/dd&
&/div& &!-- 商品循环结束 --&
%&求教求教
非常感谢!好的
写下你的评论...
写下你的评论...
问题在这里:
String sql = &select * from items where id =?;&;//SOL语句
stmt = conn.prepareStatement(sql);
rs = stmt.executeQuery();
你定义完sql语句的时候,对占位符?没有进行填充,直接就execute了,所以报错了。在execute之前用stmt.setObjec(int,Object)或stmt.setString(int,Strint)填充下sql语句再execute。
写下你的评论...
Copyright (C) 2018 imooc.com All Rights Reserved | 京ICP备 号-11JDBC连接Oracle数据库常见问题及解决方法
转载 & & 作者:
注:本文是斑竹从版摘录广大站友的提问以及各种解答整理而来,如果您认为本文的内容已触犯了您的权益,请联系管理员进行修改。
Jbuilder正确连接 oracle 9i需要注意的几个问题
oracle8以上的应该都使用classes12.jar文件作为jdbc驱动;
正确设置windows的classpath和jbuilder中的enterprise setup 、configure libraries,将casses12.jar路径正确添加到上述需要设置的地方;
进入database pilot,在database pilot中,file---new 在driver列表中如果oracle的驱动是红色的,就说明你的oralce在jb中加载失败;
若③没有错,则新建一个url:jdbc:oracle:thin:@(yourhostname):1521:(your sid)
连接数据库的Username/password
注:大部分站友的jbuilder连接oracle的问题都是由于没有正确配置classpath等引起的。
使用非XA方式连接ORACLE数据库
在windows下配置Oracle_XA时要注意两点:
#ORACLE 10Oracle_XA;%ORACLE_HOME% dbms oraxa10.lib%ORACLE_HOME%precompibmsvcorasql10.lib
#oracle 9Oracle_XA;%ORACLE_HOME% dbms oraxa9.lib%ORACLE_HOME%precompibmsvcorasql9.lib
Unix下Oracle_XA:xaosw:....
第一:在windows 下 ORACLE_XA 和xaosw后面的是分号";",不是冒号":"第二:上面的这些LIB写在一行上,中间用空格分开,如果没有在系统的环境变量中设置ORACLE_HOME,就写绝对路径。
JDBC操作ORACLE数据库时出现‘java.sql.SQLException:IO异常,不在流模式下'
用OracleStatment,,不要用java.sql.Statment
如果对已有连接进行setAutoCommit失败,则关闭该连接并重新建立一个连接
到ORACLE站点下载一个最新的JDBC Driver,如果操作LOB类型,用ORACLE自带的接口和类
weblogic连接oracle问题:The Network Adapter could not establish the connection
可能是服务器的监听停掉了,是数据库的问题,与应用无关;应该先检查一下oracle是否正常,用sql*plus连接一下数据库,看能否正常连接;
Weblogic中使用Oracle连接池及Oracle备份的注意事项
使用HP-UNIX,Weblogic 8.1,Oracle 9.2.0.5配置了一个普通的连接池,驱动程序采用oracle的Oracle's Driver(Thin) version 9.0.1, 9.2.0
错误情况:结果使用数据库连接池时报错,说没有连接池资源了。实际上数据库的连接池完全空闲,并且测试也是对的,Oracle也是正常可以连接、使用的。
问题根源:通过层层排错,发现原来后台在使用Oracle的exp备份一个只有同义词的用户,导致exp进程僵死。杀死exp、重启Oracle等无法解决问题,最终重启UNIX,禁止备份只有同义词的用户,问题解决。
总结:应该是Oracle9的exp BUG导致连接池问题,不要使用exp倒出同义词
连接Oracle时抛出如下异常:java.sql.SQLException: Io exception:The Network Adapter could not establish connection一种产生原因
Oracle Database Connection (from oracle.com)PROBLEM You are attempting to connect to an Oracle instance using JDBC and you are receiving the following error.& && java.sql.SQLException: Io exception: &&&& The Network Adapter could not establish connection&& SQLException: SQLState (null) vendor code (17002) Any or all of the following conditions may also apply:1) You are able to establish a SQL*Plus connection from the same && client to the same Oracle instance.2) You are able to establish a JDBC OCI connection, but not a Thin&& connection from the same client to the same Oracle instance.3) The same JDBC application is able to connect from a different&& client to the same Oracle instance.4) The same behavior applies whether the initial JDBC connection&& string specifies a hostname or an IP address.REDISCOVERY& To verify whether you are hitting this problem, verify whether the Oracle instance is configured for Multithreaded Server (MTS). If the Oracle instance is not configured for MTS, you are probably encountering a different problem. Otherwise, continue. Try forcing the JDBC connection to use a dedicated server instead of a shared server. This can be accomplished in several ways. For JDBC OCI or Thin, this can be done by reconfiguring the server for dedicated connections only. This approach, however, may not be feasible in many cases. In such cases, the following options apply: For JDBC OCI:&& 1) Add the (SERVER=DEDICATED) property to the TNS connect string&& stored in the tnsnames.ora file on the client.2) Set the user_dedicated_server=ON in sqlnet.ora on the client.For JDBC Thin: You must specify a full name-value pair connect string (the same as it might appear in the tnsnames.ora file) instead of the short JDBC Thin syntax. For example, instead of "jdbc:oracle:thin::port:sid"you would need to use a string of the form"jdbc:oracle:thin:@(DESCRIPTION="&&&&&&&&&&&&&&&&&&& +&&&&&&&&&&&&&&&&&&&&&& "(ADDRESS_LIST="&&&&&&&&&&&&& + &&&&&&&&&&&&&&&&&&&&&&&&&& "(ADDRESS=(PROTOCOL=TCP)" + &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& "(HOST=host)"&&& +&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& =&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& "(PORT=port)"&&& +&&&&&&&&&&&&&&&&&&&&&&&&&& ")"&&&&&&&&&&&&&&&&&&&&&& +&&&&&&&&&&&&&&&&&&&&&& ")"&&&&&&&&&&&&&&&&&&&&&&&&&& +&&&&&&&&&&&&&&&&&&&&&& "(CONNECT_DATA="&&&&&&&&&&&&& +&&&&&&&&&&&&&&&&&&&&&&&&&& "(SERVICE_NAME=sid)"&&&&& +&&&&&&&&&&&&&&&&&&&&&&&&&& "(SERVER=DEDICATED)"&&&&& +&&&&&&&&&&&&&&&&&&&&&& ")"&&&&&&&&&&&&&&&&&&&&&&&&&& +&&&&&&&&&&&&&&&&&&&& ")"If the connection works fine after having made these changes, it is very likely that this is the problem you are encountering. In this case, one last test will help to verify this fact. Log into the remote host on which the Oracle instance is running and execute the appropriate command to determine what the server 'thinks' its hostname is (i.e. the name that was configured when the server was installed and configured). For example, on a Unix host the 'hostname' command can be used for this purpose. Using the name displayed (e.g. by the hostname command), exactly as it appeared (i.e. if the output from the hostname command had the domain name included, then include it), return to the client which was unable to connect and try pinging the server. NOTE: It is critical that you attempt to ping the server using EXACTLY the same hostname you got from the server. If you are unable to ping the server via this hostname, then you almost certainly hitting this problem. If not, this may be a new issue, but at least you will have found a workaround (i.e. use a dedicated connection). EXPLANATION& To understand why this problem occurs, one must first understand the differences in how the listener handles connections to shared servers versus dedicated servers. When connecting to a dedicated server, the client connects to the listener (via hostname or IP address). The listener then spawns a dedicated server process and hands off the socket used to accept the client connection to that server. The client and server then start communicating via the endpoints established by the initial connection. NOTE: There is only one connection in this case. When connecting to a shared server, the initial client connection to the listener is the same. However, with MTS, there is no need to spawn
a pool of shared processes already exists. Also, clients do not communicate directly with the server processes in MTS; rather, they communicate with a dispatcher. For this reason, when setting up an MTS connection, the listener sends a redirect message back to the client asking the client to close the connection to the listener and connect to a dispatcher. The information in this message includes the hostname and a port number for the appropriate dispatcher. The redirect message will ALWAYS specify a hostname, even if the client initially provided an IP address. If, for any reason, the hostname provided to the listener (e.g. by the 'hostname' or another command) doesn't agree with the hostname by which the server is known on the client, the connection fails. On the other hand, if "(SERVER=DEDICATED)" already appears in the TNS connect string in tnsnames.ora or if "use_dedicated_server=ON" already appears in the sqlnet.ora file, you may find that SQL*Plus and/or JDBC OCI work fine, while JDBC Thin fails. SOLUTION& Obviously, one solution is to use dedicated servers. However, this may not always be feasible. The key is to make sure the hostname on both the client and server agree. This can be accomplished by reconfiguring either the client or the server, but there are things to be aware of in both cases. If the server is configured to return a different hostname, then it is possible that other clients which used to work will now fail. In some cases, it may not be feasible to reconfigure the client. For example, if the server version of the hostname does not include the domain, you would need to remove the domain portion of the ho but, if the client needs to connect to more than one server with the same base name in different domains, this may not be possible, as the hostname may be ambiguous. REFERENCES& bug:1269734 java.sql.SQLException: Io exception: The Network Adapter could not be found.
连接ORACLE数据库报错:javax.naming.NameNotFoundException: Unable to resolve oracThin. Resolved: '' Unresolved:'oracThin' ; remaining name ''&
问题描述:配置完JDBC后,打开页面的时候,报出如下错误信息:javax.naming.NameNotFoundException: Unable to resolve oracThin. Resolved: '' Unresolved:'oracThin' ; remaining name ''JDBC配置如下:Connection Pools(连接池)Name:OracThinURL:jdbc:oracle:thin.0.0.1:LYSIMISDriver Classname:oracle.jdbc.driver.OracleDriverProperties:user=systempassword=managerdll=ocijdbc8protocol=thin数据源配置如下:Name:OracThinJNDI Name:OracThinPool Name:OracThin当程序执行到这一步时出错。ctx = new InitialContext();ds = (javax.sql.DataSource)ctx.lookup ("OracThin");&
问题解决后汉字是乱码&
错误产生原因及解决办法:
URL:jdbc:oracle:thin:.0.0.1:1521:LYSIMI,thin后面加:,127.0.0.1后面加端口号
注意名字大小写.
target 到server上
再看看pool是否起来了,没起来的话,重起weblogic
乱码问题(Java是基于Unicode):
在JSP 文件中加入&%@ page contentType="text/ charset=GBK" %&
在weblogic.xml文件的&jsp-descriptor&部分加入&jsp-descriptor&&jsp-param&&param-name&compilerSupportsEncoding&/param-name&&param-value&true&/param-value&&/jsp-param&&jsp-param&&param-name&encoding&/param-name&&param-value&GBK&/param-value&&/jsp-param&&/jsp-descriptor&
oracle XA的疑惑
问题描述:Oracle_XA;D:oracleora92 dbmsXAORAXA9.lib C:msvcoraSQL9.lib中xaosw是什么意思
解答:可以参考ORACLE的XA部分的文档。
oracle与weblogic自动启动与停止
问题描述:每次重新启动服务器时oracle数据库若没有关闭,则必须先关闭后在重新启动redhat advance server,oracle才能够正常运行
原因及解决办法参见:
http://dev2dev.bea.com.cn/bbs/thread.jspa?forumID=81&threadID=8839&messageID=
本文整理的只是本版文章的一小部分,如果这里没有解答您的问题,请查阅本版的精华区,也可以使用论坛的搜索功能。
dev2dev ID: lhbing, dev2dev论坛版主,WebLoigc以及Java技术爱好者
您可能感兴趣的文章:
大家感兴趣的内容
12345678910
最近更新的内容
常用在线小工具jsp页面连接数据库出现了错误,运行jsp后,IE浏览器报错。哪里出现了问题?_百度知道
jsp页面连接数据库出现了错误,运行jsp后,IE浏览器报错。哪里出现了问题?
&%@ page contentType=&text/ charset=gb2312&%&
&%@ page language=&java& import=&java.sql.*,javax.sql.*& %&
//载入SQL Server 2005驱动程序
Class.forName(&com.microsoft.sqlserver.jdbc.SQLServer...
我有更好的答案
IP 连接失败com.microsoft.sqlserver.jdbc.SQLServerException: 到主机 的 TCP&#47。你数据库启动没
采纳率:29%
sa&quot.getConnection(&/127.0.0.1;1433,&quot.getConnection(&quotconn=DriverManager,&DatabaseName=TestDemo&;,&123&jdbc:sqlserver:&#47,改为:conn=DriverMjdbc:sqlserver://127.0.0.1:1433;DatabaseName=TestDemo&;,&123&冒号打成了分号;sa&);)
现在报出这样的异常了:com.microsoft.sqlserver.jdbc.SQLServerException: 到主机 的 TCP/IP 连接失败。 java.net.ConnectException: Connection refused: connect
连接失败,确认本机的SQLSERVER已经正常开启服务?
为您推荐:
其他类似问题
ie浏览器的相关知识
换一换
回答问题,赢新手礼包
个人、企业类
违法有害信息,请在下方选择后提交
色情、暴力
我们会通过消息、邮箱等方式尽快将举报结果通知您。

我要回帖

更多关于 jdbc连接mysql数据库 的文章

 

随机推荐