Jdbc--setting Usessl=false, or set usessl=true

Source: Internet
Author: User
Tags ssl connection

Today wrote a piece of code: The problem, don't panic, Baidu, solved, haha. Striking

1  Packagecn.zpoor.DBTest;2 3 ImportJava.sql.DriverManager;4 ImportJava.sql.ResultSet;5 Importjava.sql.SQLException;6 7 Importcom.mysql.jdbc.Connection;8 Importcom.mysql.jdbc.PreparedStatement;9 Ten  Public classStudents { One     Private intID; A     PrivateString name; -     PrivateString sex; -     Private intAge ; the      PublicStudents (string name, String sex,intAge ) { -          This. id = 0; -          This. Name =name; -          This. Sex =sex; +          This. Age =Age ; -     } +      Public intgetId () { A         returnID; at     } -      Public voidSetId (intID) { -          This. ID =ID; -     } -      PublicString GetName () { -         returnname; in     } -      Public voidsetName (String name) { to          This. Name =name; +     } -      PublicString Getsex () { the         returnsex; *     } $      Public voidsetsex (String sex) {Panax Notoginseng          This. Sex =sex; -     } the      Public intGetage () { +         returnAge ; A     } the      Public voidSetage (intAge ) { +          This. Age =Age ; -     } $      $      -     Private StaticConnection Getconn () { -String Driver = "Com.mysql.jdbc.Driver"; theString url = "Jdbc:mysql://localhost:3306/school"; -String username = "root";WuyiString password = "zhuqiong520"; theConnection conn =NULL; -         Try { WuClass.forName (driver);//Load Driver -conn =(Connection) drivermanager.getconnection (URL, username, password); About}Catch(ClassNotFoundException e) { $ e.printstacktrace (); -}Catch(SQLException e) { - e.printstacktrace (); -         } A         returnConn; +     } the      -     Private StaticInteger GetAll () { $Connection conn =getconn (); theString sql = "SELECT * FROM Students"; the PreparedStatement pstmt; the          the         Try { -PSTMT =(PreparedStatement) conn.preparestatement (SQL); inResultSet rs =pstmt.executequery (); the             intCol =rs.getmetadata (). getColumnCount (); theSystem.out.println ("============="); About              while(Rs.next ()) { the                  for(inti = 1;i<=col;i++) { theSystem.out.println (rs.getstring (i) + "\ T"); the                     if(i==2 && rs.getstring (i). Length () <8) { +System.out.println ("\ t"); -                     } the                 }BayiSystem.out.println (""); the             } theSystem.out.println ("============"); -}Catch(SQLException e) { - e.printstacktrace (); the         } the         return NULL; the     } the      -      Public Static voidMain (string[] args) { the Students.getall (); the     } the}







Certificate verification. =============1 Zhu Jun male 2 Wang ============

It's Java-connector-5.1.42-bin.jar.

Of course the result is right, but the above line said what UseSSL not set, Baidu a bit, is this.

Cool analysis: Mainly due to the high version of my Jar package. There is no problem with the old version, and the new version of MySQL requires an SSL connection.

Workaround: This will be a String URL = "Jdbc:mysql://localhost:3306/school?usessl=false";

EXPANSION: conn = drivermanager.getconnection ("jdbc:mysql://localhost:3306/test_db?useunicode=true&characterencoding =utf-8&usessl=false "," root "," password ");

The Useunicode settings are primarily set to utf-8 character encoding, or you can set the default character encoding in Eclipse.

        

Jdbc--setting Usessl=false, or set usessl=true

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.