使用JDBC串連mysql遇到的若干問題及解決辦法

來源:互聯網
上載者:User

標籤:增刪改查   access   jdb   false   word   127.0.0.1   ring   close   pre   

串連資料庫基本格式如下例:

 String URL="jdbc:mysql://127.0.0.1:3306/imooc?useUnicode=true&characterEncoding=utf-8";         String USER="root";         String PASSWORD="tiger";         //1.載入驅動程式         Class.forName("com.mysql.jdbc.Driver");         //2.獲得資料庫連結         Connection conn=DriverManager.getConnection(URL, USER, PASSWORD);         //3.通過資料庫的串連操作資料庫,實現增刪改查(使用Statement類)         Statement st=conn.createStatement();         ResultSet rs=st.executeQuery("select * from user");         //4.處理資料庫的返回結果(使用ResultSet類)         while(rs.next()){            System.out.println(rs.getString("user_name")+" "                          +rs.getString("user_password"));         }                //關閉資源         rs.close();         st.close();         conn.close();

問題1:No suitable driver found for jdbc

原因:URL寫錯,mysql後面少寫一個“:”

原URL:jdbc:mysql//127.0.0.1:3306/XXX

修改後URL:jdbc:mysql://127.0.0.1:3306/XXX

 

問題2:Access denied for user ‘root‘@‘localhost‘ (using password: YES)

原因:URL的連接埠寫錯了,我要連的是本地3307,錯寫成了3306。呵呵。

 

問題3:MySQL 警告WARN: Establishing SSL connection without server‘s identity verification is not recommended

這是警告不是錯誤,以後使用是不影響的。大概的意思就是說建立ssl串連,但是伺服器沒有身份認證,這種方式不推薦使用。

它不影響你訪問資料庫了。

如果你不想看到這行提示,解決辦法就是在你的URL後面加上jdbc:mysql://127.0.0.1:3306/XXX?useUnicode=true&characterEncoding=utf-8&useSSL=false

 

使用JDBC串連mysql遇到的若干問題及解決辦法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.