Tags: style class blog Code java EXT1 PackageCn.itcast.spring.jdbc;2 3 Importjava.util.List;4 5 ImportOrg.springframework.jdbc.core.support.JdbcDaoSupport;6 7 Public classPersondaoextendsjdbcdaosupport{8 Public voidUpdate () {9 This. Getjdbctemplate (). Execute ("Update person set pname= ' a ' where pid=3");Ten } One A Public voidquery () {list - for(person person:persons) { the System.out.println (Person.getpname ()); - } - } -}1 PackageCn.itc
JDBC uses database transactions and jdbc database transactions
How does a java program use jdbc to define a transaction?
Set connection to not automatically submitChange to manual submission;Write the operation database in trycatch.Throw an exceptionConnection rollback;This is a practice.Private Connection conn = null;Try {Conn. setAutoCommit (false )
stored procedures: A set of SQL statements that are compiled to complete a particular function, stored in a database, and executed by specifying the name of the stored procedure and giving parameters. Stored procedures can contain logical control statements and data manipulation statements, which can accept parameters, output parameters, return single or multiple result sets, and return values.Because stored procedures are compiled on the database server and stored in the database when they are
before manipulating Data1) Log in to the database server (mysql-u root-p password) via MySQL client tool2) Writing SQL statements3) Send SQL statement to database server execution What is jdbc? the technique of sending SQL statements using Java Code (Programs) is jdbc technology!!!! using jdbc to send sql Prerequisites
Log on to the database server (c
Document directory
Code for obtaining the primary key generatedkey. Java
JDBC obtains strong primary keys generated by the databaseHttp://blog.csdn.net/microtong
In actual development, the primary keys of tables in the database are often generated by the database. When the insert statement inserts data, fields other than the primary key are inserted. In many cases, after the insert statement is submitted to the database engine for execution, the
Insert a data entry into the database using JDBC (the first modified version), and The jdbc modified version
Added a Tools class and added some common Tools.
Package com. JDBC. java; import java. io. IOException; import java. io. inputStream; import java. SQL. connection; import java. SQL. driverManager; import java. SQL. SQLException; import java. SQL. statement
JDBC batch processing and JDBC Batch Processing
JDBC batch processing:
1) Batch Processing: process a large amount of data at a time.Explanation: Sometimes you need to send a batch of SQL statements to the database for execution. In this case, you should avoid sending and executing SQL statements to the database,
The JDBC
JDBC and jdbc connect to the database
The following is a well-behaved Java code for connecting to the database:
Class.forName("com.mysql.jdbc.Driver"); Connection conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","123456"); Statement st=conn.createStatement(); ResultSet rs=st.executeQuery("select * from student");while(rs.next()){ Object o1=rs.
Tags: a getc jdb statement MySQL processing OID pre commWhen you use spring to develop a project, all of the transactions are managed by spring. This allows us to focus on the business code without worrying about the transaction. But how does the bottom of the transaction actually be implemented? Then start learning from JDBC. When using JDBC to interact with the database, it is done through connection. B
Label:Before writing this program you need to create a Java project, which is the premise Then add the MySQL driver package, I use the database is version 5.1, so the driver package is also 5.1 version, JDK is 1.7 Create DATABASE bit mybatis, table fame user Package COM.MYBATIS.JDBC;
Import java.sql.Connection;
Import Java.sql.DriverManager;
Import java.sql.PreparedStatement;
Import Java.sql.ResultSet; /** * JDBC Operation database * @author Admini
MySQL loads the JDBC driver and mysql loads the jdbc driver.
First, install the MySQL database. MySQL5.5 is installed. The installation steps are not described here. Please note that if the installation process stops at the start service and cannot continue, please refer to my blog post "when installing MySQL5.5, the start service does not respond, solution", it should help you solve the problem.
Next,
JAVA (JDBC) Universal Query and java jdbc Universal Query
For the first time I wrote a programming blog, I hope I can correct the shortcomings.
When I recently studied mysql databases, I also looked at the java and python code. First, we can see that the java code cannot be universal. After comparing the java and python code, I think that although it cannot be as simple as python, can it be universal? Since
JDBC 5 data source and data pool (web basic learning note 11), jdbc 5I. Why are data sources and connection pools used?
Currently, the developed applications are basically data-based and require frequent database connection. If each operation is connected to the database and then disabled, the performance will be limited. Therefore, we must find a way to reuseDatabase connection. In view of this situation,
API for the JDBC interface core Java.sql.* and javax.sql.* (java2.0 later updated extensions) |-Driver Interface : Represents Java driver interface. All of the specific database vendors are going to implement this interface. |-Connect (URL, properties): a way to connect to a database. URL: The URL of the connection database URL Syntax: jdbc protocol : Database Sub-protocol :// host : Port /
Our query operations, for different data tables Examstudent and customers, there will be different code writing process, using reflection and JDBC metadata can write a common method to query different data tables.We did this before:Query the fields in the Customers table and the field values:1 PublicCustomer GetCustomer (String sql, Object ... args) {2Customer customer =NULL;3Connection Connection =NULL;4PreparedStatement PreparedStatement =NULL;5Res
Jdbc escape, jdbc
If there is such a query request, the title of the fuzzy query contains a % B _cc 'd record, the correct SQL statement should be as follows:Select * from t_sch_work_info t where t. title like '% a/% B/_ cc "d % 'escape '/';
Spring does not provide the appropriate tool class, you can use the org in the jakarta commons lang generic class package (spring/lib/jakarta-commons/commons-lang.jar
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.