ibatis查询MySQL数据库数据报错来高手指导
不要说我密码错误谢谢 我的密码很正确
以下是我的SqlIbatis.properties 文件内容
driver = com.mysql.jdbc.Driver
url = jdbc:mysql://192.168.0.220:3306/hefu_hotel
username = root
password =123456
以下是我的SqlMapConfig.xml内容
<?xml version="1.0" encoding="GBK"?>
<!DOCTYPE sqlMapConfig PUBLIC "-//ibatis.apache.org//DTD SQL Map Config 2.0//EN" "http://ibatis.apache.org/dtd/sql-map-config-2.dtd">
<sqlMapConfig>
<properties resource="com/ibatis/SqlIbatis.properties"/>
<transactionManager type="JDBC">
<dataSource type="SIMPLE">
<property name="JDBC.Driver" value="${driver}"/>
<property name="JDBC.ConnectionURL" value="${url}"/>
<property name="JDBC.Username" value="${username}"/>
<property name="JDBC.Password" value="${password}"/>
</dataSource>
</transactionManager>
<sqlMap resource="com/ibatis/mapping/User.xml" />
</sqlMapConfig>
以下是我 User.xml 的内容
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN"
"http://ibatis.apache.org/dtd/sql-map-2.dtd">
<sqlMap>
<resultMap class="com.ibatis.entity.User" id="User">
<result property="id" column="id"/>
<result property="userName" column="userName"/>
<result property="passWord" column="passWord"/>
<result property="sex" column="sex"/>
<result property="age" column="age"/>
<result property="tel" column="tel"/>
<result property="profession" column="profession"/>
<result property="mail" column="mail"/>
</resultMap>
<typeAlias alias="User" type="com.ibatis.entity.User"/>
<select id="selectUser" resultClass="User">
select * from User
</select>
</sqlMap>
以下是我的实现代码 java文件
得到SqlMapConfig.xml文件
private static SqlMapClient sqlmapClient = null;
static{
try {
Reader reader = com.ibatis.common.resources.Resources.getResourceAsReader("com/ibatis/SqlMapConfig.xml");
sqlmapClient = com.ibatis.sqlmap.client.SqlMapClientBuilder.buildSqlMapClient(reader);
reader.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
调用方法实现全查
public List<User> getAllUser() {
List<User> groupList = null;
try {
groupList =sqlmapClient.queryForList("selectUser");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return groupList;
}
下面是我所报的错误:请教高手帮忙急急急
java.sql.SQLException: Access denied for user 'root '@'welcome-PC' (using password: YES)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1055)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3558)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3490)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:919)
at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:3996)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1284)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2142)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:781)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:46)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:352)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:284)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at com.ibatis.common.jdbc.SimpleDataSource.popConnection(SimpleDataSource.java:580)
at com.ibatis.common.jdbc.SimpleDataSource.getConnection(SimpleDataSource.java:222)
at com.ibatis.sqlmap.engine.transaction.jdbc.JdbcTransaction.init(JdbcTransaction.java:48)
at com.ibatis.sqlmap.engine.transaction.jdbc.JdbcTransaction.getConnection(JdbcTransaction.java:89)
at com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.executeQueryForList(MappedStatement.java:139)
at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForList(SqlMapExecutorDelegate.java:567)
at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForList(SqlMapExecutorDelegate.java:541)
at com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.queryForList(SqlMapSessionImpl.java:118)
at com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.queryForList(SqlMapSessionImpl.java:122)
at com.ibatis.sqlmap.engine.impl.SqlMapClientImpl.queryForList(SqlMapClientImpl.java:98)
at com.ibatis.dao.imp.UserDAOimp.getAllUser(UserDAOimp.java:40)
at com.ibatis.action.UserAction.main(UserAction.java:11)
Exception in thread "main" java.lang.NullPointerException
at com.ibatis.action.UserAction.main(UserAction.java:12)
[解决办法]
貌似是没权限或者权限不足。。。
[解决办法]
授权法:
例如,你想myuser使用mypassword从任何主机连接到mysql服务器的话。
GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'%' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;
如果你想允许用户myuser从ip为192.168.1.3的主机连接到mysql服务器,并使用mypassword作为密码
GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'192.168.1.3' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;
[解决办法]
看看你mysql.user表
root用户的host配置
[解决办法]
http://blog.csdn.net/wengyupeng/article/details/3290415
[解决办法]
可以重置密码试试啊
[解决办法]
也不知道你的mysql是什么版本,建议安装5.0的。重启mysql服务,不行的话就卸了重装,
[解决办法]
你这配置文件不对啊
以下是我的SqlIbatis.properties 文件内容
driver = com.mysql.jdbc.Driver
url = jdbc:mysql://192.168.0.220:3306/hefu_hotel
username = root
password =123456
username = root ---》这里有空格
报错的也是user 'root '
我还以为你的用户名就是有空格的, 结果你说用的直接是root。。。。
[解决办法]
用户名 root 的 t 后面多写了一个空格 谢谢
[解决办法]