java - 将eclipse与数据库连接
问题描述
我编写了一个代码来连接 eclipse 和 sql server 来自动化数据库。
我曾尝试在各种网站的帮助下编写代码,但徒劳无功。
这是我写的代码:
import java.sql.*;
class mysqlcon{
@SuppressWarnings("unused")
public static void main(String args[])
{
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
String host= "localhost";
String user = "shamima";
String passwd = "Welcome@123";
try{
Class.forName("com.mysql.jdbc.Driver");
con=DriverManager.getConnection(
"jdbc:mysql://127.0.0.1:3306/eatngo",user,passwd);
stmt=con.createStatement();
rs=stmt.executeQuery("select * from
ezee_posguest_master");
while(rs.next())
System.out.println("connection
established");
con.close();
}catch(Exception e)
{
System.out.println(e);
}
}
我只是想将我的 Eclipse 与数据库连接起来。
但我得到一个错误:
“java.sql.SQLException:从服务器接收到未知的初始字符集索引'255'。可以通过'characterEncoding'属性强制初始客户端字符集。”
解决方案
字符集支持 UTF-8 它对我有用。
url=jdbc:mysql://localhost:3306/dbname?characterEncoding=utf-8&useConfigs=maxPerformance
推荐阅读
- ios - 在自定义 UIView 边框上设置渐变颜色
- jquery - 如何定位复选框标签
- java - IntelliJ - 对抛出异常的代码强加 try\catch
- c# - C# WebBrowser 控件增强保护模式
- node.js - 如何在 Dialogflow 中获得用户响应
- deployment - 如何对 nifi-famework 生成的 war 文件进行 Hot fix 部署 - NiFi
- svn - 为所有工程师阻止删除选项并仅向管理员提供相同选项的可行性
- c++ - 数据成员地址是否位于 (this) 和 (this+1) 之间?
- java - 为 ${n} 类型和 {{coinsadded}} 类型的变量创建单一模式,以便可以在字符串中找到它
- css - 远程调试时的 Safari 开发工具问题