JFinal使用筆記2-部署demo項目到Cloud Foundry

大部分步驟按cf官方的教程就能夠了。
遇到的問題以下:
一、使用C3p0Plugin配置數據庫鏈接,代碼以下
html

// 配置C3p0數據庫鏈接池插件
		//C3p0Plugin c3p0Plugin = new C3p0Plugin(getProperty("jdbcUrl"), getProperty("user"), getProperty("password").trim());
		//me.add(c3p0Plugin);
		
		String json = java.lang.System.getenv("VCAP_SERVICES");
		String dbname,username,password,host,port;
		C3p0Plugin c3p0Plugin;
		if(StringKit.isBlank(json)){
			c3p0Plugin=new C3p0Plugin(getProperty("jdbcUrl"), getProperty("user"), getProperty("password").trim());
		}else{
			JSONObject credentials = JSONObject.parseObject(json).getJSONArray("mysql-5.1").getJSONObject(0).getJSONObject("credentials");
			dbname =  credentials.getString("name");
		    username = credentials.getString("username");
			password = credentials.getString("password");
			host      = credentials.getString("host");
			port      = credentials.getString("port");
			c3p0Plugin = new C3p0Plugin("jdbc:mysql://" + host + ":" + port + "/" + dbname, username, password);
		}
		me.add(c3p0Plugin);
分本地和CF兩種狀況,能夠自適應。用到了fastjson。

以上代碼參考了這篇文章 http://abap.cloudfoundry.com/article/22.html
使用druid插件的,請看這篇文章http://www.oschina.net/code/snippet_116118_16560
二、數據庫建表,想用MySQL Workbench來建,可是用從代碼裏面獲得的ip地址,端口號,用戶名密碼來測試鏈接,連不上,問過
@Mike_Liu   以後,才成功。先open tunnel,前後顯示tunnel的info,用info裏的地址信息就能夠連上了,剩下的就跟操做本地庫同樣操做了。 java

相關文章
相關標籤/搜索