1.java connects to Oracle database
Use the following code for three steps:
Then, you can use it.
Connection connect = null;Class.forName("oracle.jdbc.driver.OracleDriver");//Add oracle driver, "" is the path of the driver String url = "jdbc:oracle:thin:@MyDbComputerNameOrIP:1521:myorcl";// For database connection, oracle represents the link to the oracle database; thin:@MyDbComputerNameOrIP represents the IP address where the database is located (thin: can be retained); 1521 represents the port number of the linked database; myorcl represents the database name String UserName = "******";// Database user login name String Password = "******";// Password connect = DriverManager.getConnection(url, UserName, Password);
2.Java connects to MySQL database
Use the following code for three steps:
Then, it can be used.
Class.forName("com.mysql.jdbc.Driver"); Connection connect = DriverManager.getConnection( "jdbc:mysql://localhost:3306/test" , // "root" , //Username "root"//Password);
The above is all the content of this article. I hope that the content of this article will be of some help to everyone’s study or work. I also hope to support Wulin.com more!