首页 > 解决方案 > 将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'属性强制初始客户端字符集。”

标签: javaseleniumjdbc

解决方案


字符集支持 UTF-8 它对我有用。

url=jdbc:mysql://localhost:3306/dbname?characterEncoding=utf-8&useConfigs=maxPerformance


推荐阅读