当前位置:网站首页>Basic introduction of JDBC
Basic introduction of JDBC
2022-07-26 08:00:00 【Super Qi】
JDBC summary
1、 Database classification
- Hierarchical database system ( from IBM The company has successfully developed )
- A mesh database system
- Relational database system ( The type of database currently applied )
- FoxBase,FoxPro,Access( Small database )
- MySQL,SQL Server,Informix( Medium database )
- Oracle,DB2,Sybase( Large databases )
2、JDBC What is it? ?
- jdbc yes Java Database connection (Java Database Connectivity,JDBC) It's a kind of execution SQL Of the statement java API(Application Programming Interface Application programming interface ), By a group java Language written classes and interfaces .
- It is a general database access interface , Can access any database .
- It provides a standard application programming interface for programmers , Developers can use pure java Language to write a complete database application

3、JDBC The role of
Establish a connection to the database
perform SQL sentence
Handle SQL The result set returned by the statement
* My summary is : Build a data path , It allows both sides to interact

4、JDBC Operating environment
Each database type needs to correspond to its own unique database driver package , such as mysql Of mysql-connector-java-5.0.4-bin.jar Driver package . other SQL Serve、DB2 And so on have their own corresponding driver packages
5、JDBC Six steps to access data
Load the database driver
// With mysql For example Class.forName("com.mysql.jdbc.Driver");Establishing a connection
String url = "jdbc:mysql://localhost:3306/test"; String username = "root"; String password = "lvzhiqi*****"; Connection conn = DriverManager.getConnection(url,username,password); //url by :"jdbc:mysql://localhost:3306/ Database name " //username by :root( Database name , Generally, the local database name is root) //password by : Database passwordestablish Statement object
Statement state = conn.createStatement();establish ResultSet Object to perform SQL sentence
String sql = "sql sentence " ResultSet rs = state.executeQuery(sql);Processing result set
while(rs.next()){ rs.getString(1);//1 Represents the position of the column in the database table rs.getString(2); rs.getString(3); }Release resources
// Create before release , Create before release try{ if(rs!=null){ rs.close(); } if(state!=null){ state.close(); } if(conn!=null){ conn.close(); } }

6、 Load driver and connection of other databases
//Oracle Mode of connection
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
String url = "jdbc:oracle:thin:@localhost:1521:orcl"; //orcl Name the database
//DB2 Mode of connection
Class.forName("com.ibm.db2.jdbc.app.DB2Driver").newInstance();
String url = "jdbc:db2://localhost:5000/test"; //test Name the database
//Sybase Mode of connection
Class.forName("com.sybase.jdbc.SybDriver").newInstance();
String url = "jdbc:sybase:Tds:localhost:5007/test"; //test Name the database
//SQL Server Mode of connection
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
String url = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=test"; //test Name the database
//Accessd Mode of connection
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection connection = DriverManager.getConnection("jdbc:odbc:test"); //test Name the database
summary :JDBC It is a general access mechanism for accessing databases , Remember the six steps :
1. Load the database driver
2. Establishing a connection
3. establish Statement object
4. establish ResultSet Object to perform SQL sentence
5. Processing result set
6. Release resources ( Create before release , Create before release )
边栏推荐
- Abstract classes and interfaces
- Summarize the common high-frequency interview questions of the software testing post
- 要不你给我说说什么是长轮询吧?
- Devaxpress.xtraeditors.datanavigator usage
- Using ordered dictionary to copy pcap files
- FTP service
- From boosting to lamdamart
- Unity metaverse (II), mixamo & animator hybrid tree and animation fusion
- JSP built-in object (implicit object) -- input / output object
- The bigger the project is, the bigger it is. This is how I split it
猜你喜欢

Dynamic performance view overview

What is message subscription and publishing?

2022-07-09 group 5 Gu Xiangquan's learning notes day02

Program environment and pretreatment

Vscode cannot start the problem solving idea

WCF deployed on IIS

The idea of stack simulating queue

Logical volume management (LVM)

Summary of distributed related interview questions

“尝鲜”元宇宙,周杰伦最佳拍档方文山将于7月25日官宣《华流元宇宙》
随机推荐
Master slave database deployment
Learning Efficient Convolutional Networks Through Network Slimming
Using ordered dictionary to copy pcap files
Table fix specific rows
Interview question set
How to determine the authenticity of the website you visit -- certificate system
Common templates for web development
Web page basic label
PyTorch
Quantitative perception training in tensorflow2.x and x86 end evaluation of tflite
Rack server expansion memory
Sort sort IP addresses
Logical volume management (LVM)
动态性能视图概述
PHP environment deployment
ARIMA model for time series analysis and prediction
现在开发人员都开始做测试了,是不是以后就没有软件测试人员了?
[fastjson1.2.24 deserialization vulnerability principle code analysis]
The difference between abstract classes and interfaces
Reading and writing properties file