Method of Java operating MySQL

This article describes the method of Java operating mysql. Share with you for your reference. The specific analysis is as follows:

Unlike the stereotype of c# manipulating the database, if you want java to manipulate the database, you can divide the statements into two types:

One is the select statement with results, and the other is the insert, into, update, delete and other statements without results

1. If it is a select statement with results, you need to define a resultset variable to connect, and use con prepareStatement(sql). executeQuery(); To query, where con is a database connection variable, and Java must be introduced into the program header sql.*, The query statement must be handled by throwing an exception, the same below. It will not be repeated. The query result can be read with the resultset variable.

For example:

2. If it is an insert, into, delete and other statements without results, it is not necessary to define any variables. Note that the query method is changed to:

that will do

I hope this article is helpful to your Java programming.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>