JAVA operation remote MySQL database for single-table additions and deletions operation

Source: Internet
Author: User

Package Mysqltest;import Java.sql.drivermanager;import Java.sql.resultset;import com.mysql.jdbc.connection;import Com.mysql.jdbc.preparedstatement;import Com.mysql.jdbc.statement;public class MysqlTest02 {public static void main ( String[] args) {//connection urlstring URL = "JDBC:MYSQL://10.1.1.136:3306/JAVADB";//connection Driverstring Driver = " Com.mysql.jdbc.Driver ";//Username String name =" root ";//password string pwd =" root "; Try{class.forname (Driver); Connection Connection = (Connection) drivermanager.getconnection (URL, name, PWD); SYSTEM.OUT.PRINTLN ("Connection Success");//Add//string sql = "INSERT into TEST (Name,func) VALUES (?,?)"; /preparedstatement statement = (preparedstatement) connection.preparestatement (SQL);//statement.setobject (1, "高文斌") ;//statement.setobject (2, "ready to find a job");//int result = Statement.executeupdate ();//if (result = = 1) {//system.out.println (" Insert Success ");//query//string SQL1 =" SELECT * from TEST WHERE ID >? ";//}//connection.commit /preparedstatement sta1 = (preparedstatement) connection.preparestatEment (SQL1);//sta1.setint (1, 1);//resultset re = Sta1.executequery ();//while (Re.next ()) {//string names = re.getstring (2);//string func = re.getstring (3);//system.out.println (names+ "\ t:" +func);//}//system.out.println ("Query Complete");////Delete String DDL = "Delete from TEST where name = ' Gao Wenbin '";//statement sta = (Statement) connection.createstatement ();//int eff = Sta.executeupdate (DDL);//system.out.println (EFF);//change Statement s = (Statement) connection.createstatement (); int B = S.executeupdate ("Update TEST set name= ' Zhou Wen King ' where name= ' John Doe '"); System.out.println (b);} catch (Exception e) {System.out.println (e);}}}

  

Preparatory work:

  1. Download Mysql-connector-java-5.1.45.zip package to Local

2. Configure the remote database configuration file, my copy is on the virtual machine, the file location in/etc/mysql/mysql.conf.d/mysqld.cnf, find bind-address = 127. 0.0. 1 commented out, allow remote access

JAVA operation remote MySQL database for single-table additions and deletions operation

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.