在NetBeans上,如果你直接在EJB專案上加入DataSourcePool基本上不會成功(至少我沒成功過...)
目前環境:NetBeans 8.2 + Glassfish 4.1
(別用Glassfish 4.1.1,那是個坑! 至少對我來說很坑)
首先要搞定Driver問題,第一步跑到MySQL官網去抓Driver
接著解壓縮之後把.jar檔copy到以下位置:
[glassfish_install_directory]/domains/
domain-name/
lib/ext/
然後到以下目錄位置:
[netbeans_install_directory]/ide/modules/ext/
找到mysql-connector-java-[version]-bin.jar
將名字複製起來,砍掉檔案,把你抓的jar檔copy進來,將名稱修改為原本的檔案名稱
以上,就是有關Driver的部分。
第二步驟,建立 JDBC Connection Pool / Resources
我懶得翻譯了,按照原文說的做理論上就沒問題了。
- Go to your Glassfish server administration panel (Link should look like this: http://localhost:4848/common/index.jsf (Under Additional Properties tab)
- Click on Services in Netbeans
- Click on Server
- Right-click on your server name [A pop-up contextual menu appears]
- Click on View Domain Admin Console [Note: Your server must be running in order to see that feature. A browser tab is automatically launched, if the server is running. You know that your server is running if you see a greenish arrow pointing to the right on the right of the server instance]
- Click on resources
- Click on JDBC
- Click on JDBC Connection Pools
- Add the following properties by clicking every time on the button Add Property (After selecting the pool name and editing it):
- driverClass: com.mysql.jdbc.Driver
- URL : jdbc:mysql://localhost/your_database_name
- password : your_password to the database management system
- serverName : localhost or your_server_name
- user : root or your_username to access the database management system
- databaseName : your_database_name
- Set up your JDBC Resources [jdbc/your_pool_name]
- Point to the specific connection pool you just setup by selecting it in the drop down box.
參考資料: