MyEclipse中建立数据源后无法连接,提示字符集错误,该怎么办?

xelam 2007-02-23 12:29:19
建立好了一个Mysql数据源但是连接得时候却有这样得错误提示:
Error while trying to longin to database
Unknown initial Character set index'48' recived from server.Initial Client character set can be forced via the 'characterEncoding' property


每回都这样,我试着用别的字符集创建数据库可是得到得结果还是一样,,,请大家指教!
...全文
534 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
xelam 2007-02-23
  • 打赏
  • 举报
回复
兄弟,,我试了这样,还是不行,错误提示仍然没变。
我换了几种字符集都不行
interpb 2007-02-23
  • 打赏
  • 举报
回复
你在url的后面加上与数据库相符的字符集看看

jdbc:mysql://localhost:3306/x2?useUnicode=true&characterEncoding=gb2312

像这样试试

xelam 2007-02-23
  • 打赏
  • 举报
回复
url:jdbc:mysql://localhost:3306/x2
字符集用了 gbk gb2312 utf-8
interpb 2007-02-23
  • 打赏
  • 举报
回复
你的数据库连接url是

还有数据库的字符集是
xelam 2007-02-23
  • 打赏
  • 举报
回复
兄弟,你帮我找得帖子已经解决问题了。呵呵
我把那帖子也转过来

运行xampp-win32-1.5.5-installer.exe,安装了xampp后,其自带的mysql是5.0.27版的,安装一切正常,成功后访问数据库也没问题,在数据库操作一切也正常。

但我写了个简单的java程序访问数据库时,却出现了问题。原程序如下:

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.ResultSet;

import java.sql.SQLException;

import java.sql.Statement;



public class DAOTest {

private static final String URL = "jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8";



private static final String USERNAME = "root";



private static final String PASSWORD = "root";



private static final String DRIVER = "com.mysql.jdbc.Driver";



public static Connection getConnection() {

try {

Class.forName(DRIVER);

return DriverManager.getConnection(URL, USERNAME, PASSWORD);

} catch (ClassNotFoundException ce) {

throw new java.lang.RuntimeException(ce);

} catch (SQLException se) {

throw new java.lang.RuntimeException(se);

}

}

public static void main(String[] args){

Connection conn=getConnection();

try{

Statement stmt=conn.createStatement();

ResultSet rs=stmt.executeQuery("select * from user");

while(rs.next())

System.out.println(rs.getString("username"));

}catch(SQLException e){

e.printStackTrace();

}

}

}

运行后问题如下:

Exception in thread "main" java.lang.RuntimeException: java.sql.SQLException: Unknown initial character set index '48' received from server. Initial client character set can be forced via the 'characterEncoding' property.

at com.kemei.database.dao.DAOTest.getConnection(DAOTest.java:25)

at com.kemei.database.dao.DAOTest.main(DAOTest.java:29)

Caused by: java.sql.SQLException: Unknown initial character set index '48' received from server. Initial client character set can be forced via the 'characterEncoding' property.

at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:910)

at com.mysql.jdbc.Connection.configureClientCharacterSet(Connection.java:2345)

at com.mysql.jdbc.Connection.initializePropsFromServer(Connection.java:3913)

at com.mysql.jdbc.Connection.createNewIO(Connection.java:2683)

at com.mysql.jdbc.Connection.<init>(Connection.java:1531)

at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:266)

at java.sql.DriverManager.getConnection(DriverManager.java:525)

at java.sql.DriverManager.getConnection(DriverManager.java:171)

at com.kemei.database.dao.DAOTest.getConnection(DAOTest.java:21)

... 1 more

从错误的提示信息中发现字符集设置出现问题,于是想到可能是xampp自带mysql的配置文件可能出有问题。于是到mysql\bin目录下,找到my.cnf,打开该文件,把

collation-server = latin1_general_ci改为collation-server = latin1_swedish_ci,重启数据库,再运行该程序,问题解决。

xelam 2007-02-23
  • 打赏
  • 举报
回复
顶...........

67,512

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧