Connect to remote database (application and database separation) bitsCN.com
Connect to a remote database (application and database separation)
If you are a database veteran, ignore it...
If you are a beginner in the database, continue...
Recently, when I was working on a project, I encountered a problem: physically separating the database from the application...
So, find information online and make a summary,
A patchwork.
Scenario and Lan are all XP systems:
PC name IP address environment configuration
PC1 192.168.0.2 application
PC2 192.168.0.3 database
1. install mysql on PC2... Please use your own Baidu; user name root, password root...
2. install ide such as myeclipse on PC1... Baidu on your own;
3.pc2run mysql.exe and the command
Grant all privileges on *. * TO 'root' @ '192. 168.0.3 'identified by 'root' with grant option;
Allow the user root to connect to the mysql server from the host whose ip address is 192.168.0.3 (if the ip address of the command line is changed to %, the user can connect to the mysql server from any address ), use root as the password. remember to flush privileges ;;
4. configure dbcp. properties of PC1. my configuration is as follows:
DriverClassName = com. mysql. jdbc. Driver
Url = jdbc/: mysql //: // 192.168.0.3/: 3306/myfirstremotedb? CharacterEncoding/= UTF-8 & zeroDateTimeBehavior/= convertToNull
Username = root
Password = root
InitialSize = 5
MaxActive = 10
MaxIdle = 10
MinIdle = 0
MaxWait = 60000
ConnectionProperties =
DefaultAutoCommit = true
(The Blue font is the database name, and the yellow background is in the same line )...
5. coding... Run! That's it!
BitsCN.com