The Oracle-based Jdbc connection technology requires a third-party jar package. You can find the corresponding jar package in the sub-package jdbc under the Oracle Installation Package, select the corresponding jar package based on the oracle version. Here I use ojdbc14.jar. First, see a class to connect to the database. In actual development, this class is used as a tool class and put into the util package.
The Oracle-based Jdbc connection technology requires a third-party jar package. You can find the corresponding jar package in the sub-package jdbc under the Oracle Installation Package, select the corresponding jar package based on the oracle version. Here I use ojdbc14.jar. First, see a class to connect to the database. In actual development, this class is used as a tool class and put into the util package.
The Oracle-based Jdbc connection technology requires a third-party jar package. You can find the corresponding jar package in the sub-package jdbc under the Oracle Installation Package, select the corresponding jar package based on the oracle version. Here I use ojdbc14.jar.
First, see a class for database connection. In actual development, this class is used as a tool class, put it in the util package, and name it JdbcUtil.
Package util; import java. SQL. connection; import java. SQL. driverManager; import java. SQL. SQLException; public class JdbcUtil {public static Connection getConnection () {Connection conn = null; String url = "jdbc: oracle: thin: @ localhost: 1521: orcl "; // urlString password = "1234"; // database password String user = "haha"; // try {Class. forName ("oracle. jdbc. oracleDriver "); // reflection mechanism, loading class driver conn = DriverManager. getConnection (url, user, password); // catch (ClassNotFoundException e) {e. printStackTrace ();} catch (SQLException e) {e. printStackTrace () ;}return conn ;}}