Basic operations on MySQL databases using java programs

Source: Internet
Author: User
Welcome to the Java Community Forum and interact with 2 million technical staff to access a series of operation code and operation result database content such as inserting, searching, and deleting MySQL database content: java source code: (the Code implements the query of the personnel information with a score of 100, and there are comments in the code of other functions) Note: run the program in eclipse

Welcome to the Java Community Forum, and interact with 2 million technical staff> enter a series of operation code and running result database content such as inserting, searching, and deleting MySQL database content: java source code: (the Code implements the query of the personnel information with a score of 100, and there are comments in the code of other functions) Note: run the program in eclipse

Welcome to the Java Community Forum and interact with 2 million technical staff> enter

Insert, search, and delete a series of operation codes and running results for MySQL database content

Database content:


Java source code: (the Code implements the query of personnel information with a score of 100. For other functions

Comments in the Code)

Note: When running a program in eclipse, You need to insert the jar package into the project; otherwise, an exception occurs!

Import java. SQL .*;

Import java. io .*;

Class database_manage {

Public Connection conn = null;

Public ResultSet rs = null;

Private String DatabaseDriver = "com. mysql. jdbc. Driver ";

// DataSource data source name DSN

Private String DatabaseConnStr = "jdbc: mysql: // localhost: 3306/lele_manage? UseUnicode = true & characterEncoding = utf8"

+ ", Root, root ";

Public void setDatabaseDriver (String Driver ){

This. DatabaseDriver = Driver;

}

Public String getDatabaseDriver (){

Return (this. DatabaseDriver );

}

Public void setDatabaseConnStr (String ConnStr ){

This. DatabaseConnStr = ConnStr;

}

Public String getDatabaseConnStr (){

Return (this. DatabaseConnStr );

}

Public database_manage () {// constructor connects to the database

Try {

Class. forName (DatabaseDriver );

} Catch (java. lang. ClassNotFoundException e ){

System. err. println ("error loading drive:" + e. getMessage ());

System. out. print ("insert execution error:" + e. getMessage (); // output to the client

}

}

[1] [2]

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.