Java link MySQL in MyEclipse

Source: Internet
Author: User
Tags exception handling mysql code

MyEclipse in Java link mysql.
Unzip the JDBC Jar file first. Configure the environment.


Below I wrote a Java program to load the JDBC driver connection to MySQL code


getconn.javapackage mysql;import java.sql.*;p ublic class getconn {    publicconnection conn = null;                         //Creating connection Objects     publicconnection getconnection ()  {                      //Get database connection method        try {         class.forname ("Com.mysql.jdbc.Driver");             //Load Database driver           string url = "Jdbc:mysql://localhost:3306/student";    // Specifies the url         string user = "root" of the connection database;                         // Specifies the user name of the database          string password = "123";                //password for the specified database           conn =drivermanager.getconnection (Url,user,password);          if  (conn !=null) {                             //If the connection instance is not empty              SYSTEM.OUT.PRINTLN ("Database connection succeeded");             //tip Information          }      }catch  ( Exception e)  {  &NBSp;      e.printstacktrace ();      }                                             //Exception Handling       return conn;                                   //return Connection Object    }    publicstatic void main  (String[]args) {                //Program Main Method       GetConn  Getconn = newgetconn ();                   //Create Getconn object       getconn.getconnection ();    }} 

The results of the implementation are as follows:

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/54/36/wKiom1R8IG2ioaGyAAQVzC2t13w463.jpg "title=" 4n$ UFNX (~8uk~~p4of4r8uy.jpg "alt=" Wkiom1r8ig2ioagyaaqvzc2t13w463.jpg "/>

This article is from the "Wu Xiaocheng" blog, make sure to keep this source http://wuxiaocheng.blog.51cto.com/9555922/1585071

Java link MySQL in MyEclipse

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.