In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces the common interfaces of JDBC, which can be used for reference. I hope you can learn a lot after reading this article. Let's take a look at it.
1.Driver interface
For every database driver, the Driver interface must be implemented. When writing the program, when you need to connect to the database, you need to load the database driver provided by the database vendor. The loading method is as follows:
Class.forname ("jdbc.driver_class_name")
It is also important to note that the java.sql package needs to be introduced first when using Class.forname. The following code is a piece of code that loads the SQL Server database driver:
Import java.sql.*;Class.forname ("com.micsoft.jdbc.sqlserver.SQLServerDriver")
2.DriverManager interface.
The DriverManager class is the management layer of JDBC, acting between the user and the driver. The DriverManager class tracks available drivers, establishes connections between the database and the corresponding drivers, and handles transactions such as driver login time control and the display of login and tracking information.
Static Conneciton getConnection (String url,String user,String password)
Url has three parts:
Jdbc::
Different parts represent different meanings:
Protocol: jdbc stands for protocol, which is the only protocol of JDBC.
Subprotocols: mainly used to identify database drivers, different database drivers have different subprotocols.
Subname: different proprietary drivers can be implemented differently.
3.Connection
The Connection object represents the connection to the database, that is, establishing a connection between the loaded Driver and the database. You must create an instance of Conneciton class.
Conneciton conn=DriverManager.getConneciton (url,user,password)
4.Statement
Statement provides the ability to run sql statements on a grass-roots connection, and the Connection interface provides a method for generating Statement.
5.ResultSet
After Statement executes the SQL statement, the result value is returned as a result set. ResultSet is the result set that contains the results of the query.
i. An example of connecting to Oracle.
Class.forname ("oracle.jdbc.driver.OracleDriver"). Newlntance (); String url= "jdbc:oracle:thin:@localhost:1521:orcl"; Sring user= "test"; String password= "test"; Connecion conn=DriverManager.getConnecion (url,user,password)
ii. Example of connecting to Sql Server
Class.forname ("com.microsoft.jdbc.sqlserver.SQLServerDriver"). Newlntance (); String url= "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=mydb"; Sring user= "ok"; String password= ""; Connecion conn=DriverManager.getConnecion (url,user,password) Thank you for reading this article carefully. I hope the article "what are the common interfaces of JDBC" shared by the editor will be helpful to you. At the same time, I also hope that you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.