Jdbc-an error has been reported when new Android users use JDBC to connect to mysql.

Source: Internet
Author: User
When an exception is thrown in logcat, the system prompts: The driver connection is successful, and the database connection fails. Couldnotfindclass & #39; javax. naming. StringRefAddr & #39;, referencedfrommethodcom. mysql. jdbc. connectionproperti. Please help me. the error revolves around connecting code & quot; to the database publicstaticConnectiongetCon () {Conn mysqljdbc database android

If an exception is thrown at logcat, the system prompts: The driver connection is successful, and the database connection fails. cocould not find class 'javax. naming. StringRefAddr ', referenced from method com. mysql. jdbc. ConnectionPropertiesImpl $ ConnectionProperty. storeTo. Please help me. the error has been around for a long time.

Connection code

// Connect to the database public static Connection getCon () {Connection conn = null; try {Class. forName ("org. gjt. mm. mysql. driver "); System. out. println ("successful driver connection");} catch (ClassNotFoundException e1) {// TODO Auto-generated catch block System. out. println ("driver connection failed");} String dbUrl = "jdbc: mysql: // localhost: 3306/student"; String username = "root "; string PSWs = "1234"; try {conn = DriverManager. getConnection (dbUrl, username, psw);} catch (SQLException e) {// TODO Auto-generated catch block System. out. println ("database connection failed" + e);} return conn ;}
Related Article

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.