Java operations on mysql database (connection, addition, deletion, modification and query)

java operation on mysql database(connection,add, delete, modify) environment:myeclipse 2014 + tomcat + mysql ( Navicat for mysql) 1. Implement query: package com.mysql;import java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement; public class DBChaxun {private static final String url &#61 ; “jdbc:mysql://localhost:3306/web”;private static final String user = “root”;private static final String password = “root”;public static void main(String[] args ) throws ClassNotFoundException, SQLException {//1. Load the driver (mysql) Class.forName(“com.mysql.jdbc.Driver”); //2. Get the database connection Connection conn = DriverManager.getConnection(url , user, password); //3. Operate the database through database connection , to implement addition, deletion, modification and query Statement stmt = conn.createStatement(); //Create statement object ResultSet rs = stmt.executeQuery (“select name, age from info”); //(1) Implement the query function , and return the resultset object //4. Get the data in the resultset object while(rs.next()){System.out. println(rs.getString(“name”)+rs.getInt(“age”));}}} 2. Implement deletion: package com.mysql;import java.sql.Connection;import java .sql.DriverManager;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;public class DBDelete {private static final String url = “jdbc :mysql://localhost:3306/web”;private static final String user = “root”;private static final String password = “root”;public static void main(String[] args) throws ClassNotFoundException , SQLException {//1. Load the driver (mysql) Class.forName(“com.mysql.jdbc.Driver”); //2. Get the database connection Connection conn = DriverManager.getConnection(url, user, password); //3. Operate the database through database connection , to implement addition, deletion, modification and…

MongoDB (6) java operation mongodb addition, deletion, modification and query

We already know the code of Java operating mysql database very well, such as addition, deletion, modification and query. Java also performs similar operations on mongodb database. First, connect to the database, and then perform operations. First we enter the admin database, and then create our own database testMongoDb. After entering the admin database, we can directly enter testMongoDb, because users can We already know the code of Java operating mysql database very well, such as adding, deleting, modifying and checking. Java also performs similar operations on mongodb database. The database connection is first, and then the operation is performed. First we enter the admin database, and then create our own database testMongoDb. After entering the admin database, we can directly enter testMongoDb, because the user can enter the system database, which is the super administrator. After use testMongoDb, set the user for the database name and password, db.addUser('root','root'). In this way, we can connect to the database in the program and implement addition, deletion, modification and query. The code is as follows. The code is as follows: package com.mkyong.core; import java.net.UnknownHostException; import java.util.Date; import com.mongodb.BasicDBObject; import com.mongodb.DB; import com.mongodb.DBCollection; import com.mongodb.DBCursor; import com.mongodb.Mongo; import com.mongodb.MongoException; /** * Java +…

Java operation mongodb: basic addition, deletion, modification and query

Java code for operating mongodb, including basic add, delete, modify and query operations to obtain the database connection tool class package com.liuc.db;import java.net.UnknownHostException;import com.mongodb.DB;import com. mongodb.DBCollection;import com.mongodb.Mongo;/** * * @brief MongoDBUtil.java operation Java code for operating mongodb, including basic add, delete, modify and query operations Get the database connection tool class package com.liuc.db; import java.net.UnknownHostException; import com.mongodb.DB; import com.mongodb.DBCollection; import com.mongodb.Mongo; /** * * @brief MongoDBUtil.java operating mongodb tool class * @attention Notes on usage * @author liuchao * @date 2013-12-30 * @note begin modify by Modifier Modification time Summary of modification content */ public class MongoDBUtil { /** * * \brief Obtain database connection without authentication * @return * Precautions for using @attention method * @author liuchao * @date 2013-12-30 * @note begin modify by Modifier Modification time Summary of modification content */ public static DBCollection getDBConnectionWithoutAuth(String colName){ try { Mongo mOngo= new Mongo(“localhost”, 27017); DB db = mongo.getDB(“liuchao”); return db.getCollection(colName); } catch (UnknownHostException e) { e.printStackTrace(); return null; } } /** * Obtain the database connection that requires authentication Start login password authentication: Log in to the database and add users use db.addUser('user1','pwd1'); Restart the server and enable the authentication service mongod –auth –dbpath=D:\mongodb\db Next, you will need…

MongoDB (6) java operation mongodb addition, deletion, modification and query

We already know the code of Java operating mysql database very well, such as addition, deletion, modification and query. Java also performs similar operations on mongodb database. First, connect to the database, and then perform operations. First, we enter the admin database, and then create our own database testMongoDb. After entering the admin database, we can directly enter testMongoDb, because users can java operate the mysql database code. We already know everything about it, adding, deleting, modifying, and checking. Java also performs similar operations on the mongodb database. The database is connected first, and then the operation is performed. First we enter the admin database, and then create our own database testMongoDb. After entering the admin database, we can directly enter testMongoDb, because users can enter the system database and are super administrators. After use testMongoDb, Set the user name and password for the database, db.addUser('root','root'), so that we can connect to the database in the program and implement additions, deletions, modifications and queries. The code is as follows. package com.mkyong.core; import java.net.UnknownHostException; import java.util.Date; import com.mongodb.BasicDBObject; import com.mongodb.DB; import com.mongodb.DBCollection; import com.mongodb.DBCursor; import com.mongodb.Mongo; import com.mongodb.MongoException; /** * Java + MongoDB Hello world Example * */ public class App…

Basic knowledge of Java connection to JDBC (operating database: addition, deletion, modification and query)

1. Introduction to JDBC JDBC is the bridge between Java applications and databases. What is JDBC? A specification for Java language to access databases, which is a set of APIs. JDBC (Java Database Connectivity) API, the Java Database Programming Interface, is a set of standard interfaces and classes in the Java language. Using these interfaces and classes, Java client programs can access various types of databases. For example, establishing a database connection and executing SQL statements to access data. JDBC stands for Java Database Connectivity. The API tasks contained in the JDBC library are commonly used with databases: Connect to database Create SQL or MySQL statements Execute SQL or MySQL queries in the database View and modify records For example: 2. Detailed explanation of JDBC usage 1. Open the database First create a new Java project and import the jar package into it: Then create the corresponding database and table. Write DBUtil.java package com.study.db; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement; public class DBUtil { private static final String URL=”jdbc:mysql://localhost:3306/demo_jdbc”; private static final String NAME=”root”; private static final String PASSWORD=”root”; public static void main(String[] args) throws Exception{ //1.Load driver Class.forName(“com.mysql.jdbc.Driver”); //2. Obtain the database connection Connection cOnn= DriverManager.getConnection(URL, NAME,…

Simple implementation of javascriptjs operation array addition, deletion, modification and query

Function definition Array.prototype.indexOf = function(val) { for (var i = 0; i -1) { this.splice(index, 1); } }; Array.prototype.insert = function (index, item) { this.splice(index, 0, item); }; Use: myarray.remove(i); //Delete //Update myarray.remove(0); myarray.insert(0,eventjson[0]); //Insert myarray.insert(0,eventjson[0]); The above simple implementation of Javascript js operation array addition, deletion, modification and search is all the content shared by the editor. I hope it can give you a reference and hope you will support it.

Java basic development JDBC operation database addition, deletion, modification and query, detailed explanation of paging query examples

The operations on the database are nothing more than additions, deletions, modifications and queries, among which the numerical query operation is the most complex, so the query will be explained separately. The Mysql database I use here Add, delete, modify and check operations Paging query operation 1. Query results are returned in list 2. Query results are returned as jsonArray 3. Query the total number of records Let’s take a look at the relevant configuration information first public static final String USER_NAME = “root”; public static final String PWD = “123456789”; public static final String DRIVER = “com.mysql.jdbc.Driver”; public static final String URL = “jdbc:mysql://localhost:3306/web_demon”; /** Paging query default number of records per page */ public static final int PAGE_SIZE_DEFAULT = 10; Add, delete, and modify operations Get the database connection object /** * Get database connection * @return database connection object */ public Connection getConnection(Connection conn) { if(cOnn== null){ try { Class.forName(Config.DRIVER); cOnn= DriverManager.getConnection(Config.URL, Config.USER_NAME, Config.PWD); } catch (Exception e) { e.printStackTrace(); } } return conn; } Encapsulate addition, deletion and modification operations /** * Add, delete, insert operations * @param sql sql statement executed * For example: add the statement “insert into user (name,sex) values ​​(?,?)”; * Delete…

12-9java web database addition, deletion, modification and check

129javaweb database addition, deletion, modification and query

First of all, the general java structural framework is like this A very important point is to establish a database connection The database is the prerequisite for all operations, whether it is adding, deleting, modifying or querying, you need to call the database connection program Then there is the writing of java classes. After writing the classes, you need to add, delete, modify and check methods This is the operation of adding, deleting, modifying and checking at the dao layer This is the writing of the class severlet is the interface between jsp and database The following is the general structure of establishing a jsp web interface A jar package is required to connect to the database There must be attributes such as id in the database.

java database ppt, java database addition, deletion, modification and query

List of contents of this article: 1. How to upload and download ppt on java web? Does it need to be uploaded to the server? Excel can do it, but how to save this ppt to the database? 2. How to use JAVA to connect to the database? 3. Java reads the jpg uploaded by the user. pdf, doc, xls, ppt files, store the binary data of these files in the database, or store them in file form How to upload and download ppt on java web? Does it need to be uploaded to the server? Excel can do it, but how to save this ppt to the database? If you upload it, it must be uploaded to the server. Otherwise, where can you save it? The file can be converted into binary, and the file can be stored in the database as blob type, but this is not recommended as it will reduce the database performance. Generally, it is stored in a special place on the server, and only the path, upload time and other information are saved in the database How to use JAVA to connect to the database? 1. Load the driver. 2. Create a connection object.…

Java connects to oracle for addition, deletion, modification and query

Java connects to oracle for addition, deletion, modification and query

1. Add class OraclePersionDao to the DAO layer package com.test.dao;import java.sql.*;/** * Created by wdw on 2017/9/16. */public class OraclePersionDao { // Database driver class private String dbDriver = “oracle.jdbc.driver.OracleDriver”; //Connect to database url private String dbURL = “jdbc:oracle:thin:@192.168.31.128:1521:orcl “; // Username to connect to the database private String dbUser = “PHIP”; //Connect to database password private String dbPwd = “PHIP”; // Get the database connection method and return the Connection object private Connection con = null; //Data execution statement private Statement stat = null; private String sql = null; private ResultSet rs = null; //Create database connection public Connection getDBConnect() { try {// Load database driver Class.forName(dbDriver); con = DriverManager.getConnection(dbURL, dbUser, dbPwd); } catch (Exception e) { System.out.println(e); } return con; } //Add public void Add() { con = getDBConnect(); sql = “insert into sys_users(id,code,name )” + “values(‘1′,’lucy’,’w’)”; try { stat = con.createStatement(); stat.executeUpdate(sql); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } //Delete public void Delete( ) { con = getDBConnect(); sql = “delete from sys_users ” + “where ID=1”; try { stat = con.createStatement(); stat.executeUpdate(sql); } catch (SQLException e) {// TODO Auto-generated catch block e.printStackTrace(); } } //Modify public void Update() { con…

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索