java串連資料庫時jdbc設定編碼,javajdbc

來源:互聯網
上載者:User

java串連資料庫時jdbc設定編碼,javajdbc

發現網上很多坑爹貨,有很多意思表達不全,比如jdbc串連mysql資料庫的時候,設定字元集編碼


可以如下配置,mysql可直接在url後面加上字元集設定:


...省略

String url = "jdbc:mysql://localhost:3306/exceltest1?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull";
String username = "root";
String password = "123456";

...省略


但是oracle串連的話就不行,他會提示找不到SID。

錯誤例子如下:

url=jdbc:oracle:thin:@192.168.1.233:1521:oradbcharacterEncoding=UTF-8

其實oracle的字元集,預設的就是資料庫字元集,查看資料庫字元集的方法:

select userenv('language')from dual;

下面是修改oracle資料庫字元集的辦法(網上搜的):

修改oracle資料庫字元集的辦法

個人選擇了備份資料庫,然後刪除原有庫,建立資料庫,設定字元集,然後倒入備份~

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.