项目运行时出现java.sql.SQLException: Server configuration denies access to data source错误!

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了项目运行时出现java.sql.SQLException: Server configuration denies access to data source错误!相关的知识,希望对你有一定的参考价值。

Initializing c3p0 pool... com.mchange.v2.c3p0.PoolBackedDataSource@125f76b [ connectionPoolDataSource -> com.mchange.v2.c3p0.WrapperConnectionPoolDataSource@1ddd83c [ acquireIncrement -> 1, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 0, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, idleConnectionTestPeriod -> 3000, initialPoolSize -> 50, maxIdleTime -> 6000, maxPoolSize -> 500, maxStatements -> 1500, maxStatementsPerConnection -> 0, minPoolSize -> 50, nestedDataSource -> com.mchange.v2.c3p0.DriverManagerDataSource@d27bb0 [ description -> null, driverClass -> null, factoryClassLocation -> null, jdbcUrl -> jdbc:mysql://localhost:3306/cwerp090930, properties -> user=******, password=****** ] , preferredTestQuery -> null, propertyCycle -> 300, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, usesTraditionalReflectiveProxies -> false ] , factoryClassLocation -> null, numHelperThreads -> 3, poolOwnerIdentityToken -> 125f76b ]
java.sql.SQLException: Server configuration denies access to data source
at org.gjt.mm.mysql.MysqlIO.init(Unknown Source)
at org.gjt.mm.mysql.Connection.connectionInit(Unknown Source)
at org.gjt.mm.mysql.jdbc2.Connection.connectionInit(Unknown Source)
at org.gjt.mm.mysql.Driver.connect(Unknown Source)
at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:68)
at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:87)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1.acquireResource(C3P0PooledConnectionPool.java:83)
at com.mchange.v2.resourcepool.BasicResourcePool.assimilateResource(BasicResourcePool.java:884)
at com.mchange.v2.resourcepool.BasicResourcePool.acquireUntil(BasicResourcePool.java:601)
at com.mchange.v2.resourcepool.BasicResourcePool.access$400(BasicResourcePool.java:31)
at com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1079)
at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:354)

数据库是mysql
用的是resin3 +myeclipse5.5 +mysql5 是不是有可能是驱动问题

参考技术A 在自用的机子上安装了redhat9.0+Tomcat5.0+JDK1.5+JBuilder9.0+weblogic8.X的机子上开发jsp,在vi /etc/profile 配置好以后:
JAVA_HOME=/usr/java/jdk
export JAVA_HOME

PATH=$JAVA_HOME/bin:JAVA_HOME/jre/bin:$PATH
export PATH
CLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/lib/dt.jar:JAVA_HOME/lib/tools.jar:$JAVA_HOME/jre/lib:$TOMCAT_HOME/common/lib:$JAVA_HOME/jre/lib/ext/mysql-connector-java-3.1.12-bin.jar
export CLASSPATH
CATALINA_HOME=/opt/tomcat
export CATALINA_HOME
CATALINA_BASE=/opt/tomcat
export CATALINA_BASE
TOMCAT_HOME=/opt/tomcat
export TOMCAT_HOME

将mysql的驱动程序mysql-connector-java-3.1.12-bin.jar放置在Tomcat_home/command/lib目录下。
用一测试文件test.jsp测试能否连接数据库:
<%@ page contentType="text/html; charset=UTF-8" %>
<%@ page import="java.sql.*"%>
<html>
<head>
<title>
testmysql
</title>
</head>
<body bgcolor="#ffffff">
<%Class.forName("com.mysql.jdbc.Driver").newInstance();

String url="jdbc:mysql://localhost/test";
String username="lenovo";
String password="lenovo";
Connection conn=DriverManager.getConnection(url,username,password);
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql="select * from test";
ResultSet rs=stmt.executeQuery(sql);
while(rs.next())
%>
your first data:<%=rs.getString(1)%>
your second data:<%=rs.getString(2)%>
<%%>
<%out.print("mysql opration is success");%>
<%rs.close();
stmt.close();
conn.close();%>
</body>
</html>

在mysql内建立测测试数据库test,表test
create table test(col1 varchar(10),col2 varchar(10));

insert into test(col1,col2)values(aaa,bbb);

结果jsp访问数据库的时候出现错误:Server configuration denies access to data source.
首先觉得是数据库的用户或者权根不正确。在字符模下mysql -u root -p登录数据库,对其进行管理
输入:
GRANT ALL PRIVILEGES ON *.* TO root@localhost IDENTIFIED BY "password";
FLUSH PRIVILEGES;

测试jsp,还是不行,
通过:telnet localhost 3306,结果出现:
KHost 'localhost.localdomain' is not allown to connect to this mysql serverConnection closed by
foreign host.
于是登入数据库

GRANT ALL PRIVILEGES ON *.* TO root@localhost.localdomain IDENTIFIED BY "password";
FLUSH PRIVILEGES;

之后一切正常

后想起来可能是前面装了weblogic产生的本回答被提问者采纳

以下错误是啥意思:java.sql.sqlexception 在索引处缺少输入或输出参数

【中文标题】以下错误是啥意思:java.sql.sqlexception 在索引处缺少输入或输出参数【英文标题】:what does the following error mean: java.sql.sqlexception missing in or out parameter at index以下错误是什么意思:java.sql.sqlexception 在索引处缺少输入或输出参数 【发布时间】:2011-08-08 02:12:06 【问题描述】:

在处理一些 JDBC 代码时出现以下错误:

java.sql.sqlexception missing in or out parameter at index: 6

有人能解释一下这是什么意思吗?更一般地说,是否有一个网站/一组文档可以解释错误声明的含义?

【问题讨论】:

【参考方案1】:

你有这样的声明:

select foo from bar where a=? and b=? and c=? ...

您的代码将值绑定到参数:

st.setInteger(1,123); // goes to a
st.setString(2,"hello"); // goes to b
...

现在,参数 #6 未绑定,未提供任何值。语句不知道将什么值发送到 DB(默认情况下它不会发送 NULL)。如果参数值未知,你应该这样做:

st.setNull(6,Types.VARCHAR);

【讨论】:

【参考方案2】:

您可以粘贴您的 PreparedStatement 代码吗?这意味着你有一个额外的?在您没有为其设置值的语句中。

【讨论】:

以上是关于项目运行时出现java.sql.SQLException: Server configuration denies access to data source错误!的主要内容,如果未能解决你的问题,请参考以下文章

运行php项目时出现白屏

运行spring boot项目时出现SQLSyntaxErrorException

运行 Spring Boot cassandra 项目时出现异常

在 Typescript 项目上运行业力覆盖时出现意外令牌

使用 xampp 运行本地项目时出现致命错误

在我的反应 js 项目中运行 npm start 时出现白屏