Java connection to the database
A few notes about connecting Java to the database
1. connect java to the Oracle database
Use the following code to perform three steps:
1. Download The ojdbc. jar package and import it to the project. Appendix: http://download.csdn.net/detail/zy5669536/2606669
2. Place the following code where you think it should be.
3. modify the code: Change MyDbComputerNameOrIP to the IP address of the computer where the Oracle database is located, and change UserName and Password to the user name and Password defined earlier.
Then, you can use it.
Connection connect = null; Class. forName ("oracle. jdbc. driver. oracleDriver "); // Add the oracle Driver." "contains the driver path String url =" jdbc: oracle: thin: @ MyDbComputerNameOrIP: 1521: myorcl "; // database connection. oracle indicates connecting to the oracle database; thin: @ MyDbComputerNameOrIP indicates the IP address of the database (thin can be retained :); 1521 indicates the port number of the connected database; myorcl indicates the database name.
String UserName = "*******"; // Database User Login Name
String Password = "*******"; // Password
Connect = DriverManager. getConnection (url, UserName, Password );
2. connect Java to the MySQL database
Use the following code to perform three steps:
1. Download The mysql-jdbc.jar package and import it to the project. Appendix: http://download.csdn.net/detail/u010032692/5180868
2. Keep the following code where you think it should be.
3. modify the code: Change localhost to the IP address of the computer where the MySQL database is located, change test to the database name, and change root to the user name and password defined earlier.
Then, you can use it.
Class. forName ("com. mysql. jdbc. driver "); Connection connect = DriverManager. getConnection ("jdbc: mysql: // localhost: 3306/test", // "root", // username "root" // password );