Java - Oracle 連線使用 tnsname
web server 必需安裝 oracle client,然後設定好 tnsnames.ora
<tnsname> =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(Host = <hostname>)(Port = <port>))
)
(CONNECT_DATA =
(SERVICE_NAME = <sid>)
)
)
connection string 中的 url 由原本的 jdbc:oracle:thin:@<hostname>:<port>:<sid>
改成 jdbc:oracle:thin:@<tnsname>
然後要讓程式知道 tnsnames.ora 的位置,有二個方法:
1. java 程式在資料庫 open session 前設定系統變數
System.setProperty("oracle.net.tns_admin", "D:/oracle/product/10.2.0/client_1/NETWORK/ADMIN");
2. 將設定加入 tomcat7w 或是啟動 sh 中
-Doracle.net.tns_admin=D:/oracle/product/10.2.0/client_1/NETWORK/ADMIN
2015年4月20日 星期一
2013年11月20日 星期三
使用 MSIEXEC.EXE 安裝 msi 時,指定 All Users
MSIEXEC.EXE /I MyPackage.msi
When no value is specified the application is installed "Per User" placing shortcuts in the current user profile.
When no value is specified the application is installed "Per User" placing shortcuts in the current user profile.
MSIEXEC.EXE /I MyPackage.msi ALLUSERS=1
This installs shortcuts to the "All Users" profile, only administrators will be able to install the shortcuts in this way.
This installs shortcuts to the "All Users" profile, only administrators will be able to install the shortcuts in this way.
MSIEXEC.EXE /I MyPackage.msi ALLUSERS=2
For users, this will install the shortcut in the current user profile, for administrators, this will still install the profile for "All Users". As an administrator, if you wish to install the shortcuts in your own local profile, do not specify a value for the ALLUSERS property.
For users, this will install the shortcut in the current user profile, for administrators, this will still install the profile for "All Users". As an administrator, if you wish to install the shortcuts in your own local profile, do not specify a value for the ALLUSERS property.
Taken from: http://www.appdeploy.com/faq/detail.asp?id=69
Nicholas Jones, MCITP® | Core Infrastructure Consultant | Sparkhound | https://www.mcpvirtualbusinesscard.com/VBCServer/nicholas.jones/profile
參考網址: http://social.technet.microsoft.com/Forums/systemcenter/en-US/6c0e5bd6-94f1-4d77-b361-e17ecba9783d/sccm-msi-and-allusers-property
2013年10月28日 星期一
RegistryKey.SetValue 遇到 UnauthorizedAccessException
參考網址: http://stackoverflow.com/questions/11768172/c-sharp-registry-setvalue-throws-unauthorizedaccessexception
string user = Environment.UserDomainName + "\\" + Environment.UserName
RegistryAccessRule rule = new RegistryAccessRule(user,
RegistryRights.FullControl,
AccessControlType.Allow);
RegistrySecurity security = new RegistrySecurity();
security.AddAccessRule(rule);
var key = Microsoft.Win32.Registry.Users.OpenSubKey(Path, RegistryKeyPermissionCheck.ReadWriteSubTree, RegistryRights.FullControl);
key.SetAccessControl(security);
2013年9月27日 星期五
javax.xml.ws.WebServiceException: 無法建立 JAXBContext
使用 web service 時如果有 throw exception 的話,會遇到 "javax.xml.ws.WebServiceException: 無法建立 JAXBContext" 的錯誤
java.security.PrivilegedActionException: com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions java.lang.StackTraceElement does not have a no-arg default constructor.
把 throw exception 拿掉,改用 try..catch 就可以了
java.security.PrivilegedActionException: com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions java.lang.StackTraceElement does not have a no-arg default constructor.
把 throw exception 拿掉,改用 try..catch 就可以了
2013年9月26日 星期四
javascript 執行減法運算
在 javascript 執行 float 相減時,可能會發生 9.700000000000001 的情形
為防止這個情形發生,必需加上 .toFixed()
例如:
var i = 9.8;
i = (i - 0.1).toFixed(1); // i => 9.7
2013年9月18日 星期三
備份系統安全性記錄檔
參考來源: http://jojochen.blog.ithome.com.tw/post/2529/77642
參考來源: http://msdn.microsoft.com/en-us/library/aa394593%28v=VS.85%29.aspx
以下為 vbs 內容:
=============================
'定義變數BackupName備份事件檢視器檔案
Dim BackupName
Set Fso = CreateObject("Scripting.FileSystemObject")
'定義當日年,月,日
dtmThisDay = Day(Date)
dtmThisMonth = Month(Date)
dtmThisYear = Year(Date)
strBackupName = dtmThisYear & "_" & dtmThisMonth & "_" & dtmThisDay
'設定 WMI 取得 NameSpace 為 root\cimv2 的 Backup 方式
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate,(Backup,Security)}!\\.\root\cimv2")
'WQL 取得 Win32_NTEventLogFile 為安全性記錄檔 security
Set colLogFiles = objWMIService.ExecQuery("Select * from Win32_NTEventLogFile Where LogFileName='security'")
For Each objLogfile in colLogFiles
BackupName = "c:\" & strBackupName & "_security.evt"
if (Fso.FileExists(BackupName)) then
objLogFile.BackupEventLog("c:\" & strBackupName & "_security2.evt")
objLogFile.ClearEventLog()
WScript.Echo "File saved: " & strBackupName & "_security2.evt"
else
objLogFile.BackupEventLog("c:\" & strBackupName & "_security.evt")
objLogFile.ClearEventLog()
WScript.Echo "File saved: " & strBackupName & "_security.evt"
end if
Next
Set colLogFiles = Nothing
Set objWMIService = Nothing
Set Fso = Nothing
=============================
更新:
在 windows 2000 執行時遇到 SWbemObject: Access denied 存取遭到拒絕
將 impersonationLevel=impersonate,(Backup) 改成 impersonationLevel=impersonate,(Backup,Security)
2013年9月14日 星期六
解決 sencha touch 2.2.x 在 Chrome 29.x 執行時,textfield 無法顯示的問題
參考來源:http://druckit.wordpress.com/2013/08/22/sencha-touch-2-x-and-google-chrome-29/
There’s a bug in Google Chrome 29 that prevents Sencha Touch 2.2.x apps from displaying properly. While this shouldn’t affect mobile browsers (yet), it will affect you if you use Chrome to debug your apps.
You can patch your Sencha Touch 2.2.x apps by modifying the /touch2/resources/themes/stylesheets/sencha-touch/base/mixins/_Class.scss file, replacing the st-box mixin with the following code:
1
2
3
4
5
6
7
8
9
10
11
| @mixin st-box($important: no) { @if $important == important { display: flex !important; display: -webkit-box !important; display: -ms-flexbox !important; } @else { display: flex; display: -webkit-box; display: -ms-flexbox; }} |
修改後,必需重新 compile
切換到 /Project/resources/sass 目錄下,執行 compass watch .
2013年8月30日 星期五
response.setHeader 下載檔名遇到中文字的解決方法
response.setContentType("application/x-x509-ca-cert");
response.setContentLength(byteCert.length);
// caname 是中文字
// Safari & Firefox & Chrome
String fileName = new String(caname.getBytes(), "ISO8859-1");
String agent = request.getHeader("USER-AGENT");
if (null != agent && -1 != agent.indexOf("MSIE")) {
// IE
fileName = URLEncoder.encode(fileName, "UTF8").replaceAll("\\+", "%20");
}
response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + ".cer\"");
2013年8月23日 星期五
解決 Linux 主機使用 KeyStore 儲存 pfx 時非常慢的問題
在啟動的 shell script 中 (catalina.sh) 加上下列指令
export JAVA_OPTS="$JAVA_OPTS -Djava.security.egd=file:/dev/./urandom"
2013年8月22日 星期四
從 web service 取得 ServletContext 物件
// ServletContextListener Class
public void contextInitialized(ServletContextEvent sce) {
try {
sce.getServletContext().setAttribute("myBook", "Learning java");
} catch (Exception ex) {
}
}
// WebService
@Resource
WebServiceContext wsContext;
@WebMethod(operationName = "test1")
public String test1() {
ServletContext servletContext = (ServletContext) wsContext.getMessageContext().get(MessageContext.SERVLET_CONTEXT);
String myBook = (String) servletContext.getAttribute("myBook");
}
public void contextInitialized(ServletContextEvent sce) {
try {
sce.getServletContext().setAttribute("myBook", "Learning java");
} catch (Exception ex) {
}
}
// WebService
@Resource
WebServiceContext wsContext;
@WebMethod(operationName = "test1")
public String test1() {
ServletContext servletContext = (ServletContext) wsContext.getMessageContext().get(MessageContext.SERVLET_CONTEXT);
String myBook = (String) servletContext.getAttribute("myBook");
}
2013年8月14日 星期三
Get viewport size (Nice)
var w = window,
d = document,
e = d.documentElement,
g = d.getElementsByTagName('body')[0],
x = w.innerWidth || e.clientWidth || g.clientWidth,
y = w.innerHeight|| e.clientHeight|| g.clientHeight;
alert(x);
alert(y);
Reference url: http://stackoverflow.com/questions/3437786/how-to-get-web-page-size-browser-window-size-screen-size-in-a-cross-browser-wa
2013年7月31日 星期三
Post data to a new window with full screen
Javascript Example:
function postDataToNewWindow() {
var myform = document.createElement("form");
myform.setAttribute("method", "post");
myform.setAttribute("action", "verifyCredential.asp");
myform.setAttribute("target", "_custom");
var hiddenField = document.createElement("input");
hiddenField.setAttribute("type", "hidden");
hiddenField.setAttribute("name", "credential");
hiddenField.setAttribute("id", "credential");
hiddenField.setAttribute("value", "2.0");
myform.appendChild(hiddenField);
document.body.appendChild(myform);
window.open("", "_custom", "fullscreen=yes");
myform.submit();
}
function postDataToNewWindow() {
var myform = document.createElement("form");
myform.setAttribute("method", "post");
myform.setAttribute("action", "verifyCredential.asp");
myform.setAttribute("target", "_custom");
var hiddenField = document.createElement("input");
hiddenField.setAttribute("type", "hidden");
hiddenField.setAttribute("name", "credential");
hiddenField.setAttribute("id", "credential");
hiddenField.setAttribute("value", "2.0");
myform.appendChild(hiddenField);
document.body.appendChild(myform);
window.open("", "_custom", "fullscreen=yes");
myform.submit();
}
2010年9月21日 星期二
使用 jquery 設定 tag 的屬性值
設定 mobile 欄位為唯讀
$("#mobile").attr('disabled', true);
$("#mobile").attr('disabled', true);
判斷 checkbox 欄位是否被勾選
$("#checkbox_id").attr('checked');
java 編譯時出現 "unchecked call to put(K,V)..." 的警告訊息
程式碼 Map result = new HashMap(); 在編譯時出現以下的警告訊息
warning: [unchecked] unchecked call to put(K,V) as a member of the raw type java.util.Map
解決方法,將程式碼改成以下的方式
Map<Object,Object> result = new HashMap<Object,Object>();
warning: [unchecked] unchecked call to put(K,V) as a member of the raw type java.util.Map
解決方法,將程式碼改成以下的方式
Map<Object,Object> result = new HashMap<Object,Object>();
2010年9月20日 星期一
2010年9月16日 星期四
使用 NetBeans 在 Mac 上開發 java web application 時遇到的問題
Q: 連線 MySQL 時出現 "Host 192.168.232.108 is not allowed to connect to this MySQL server"
A:
1. 開啟 Server 上的 MySQL Administrator
2. 選擇 User Administration
3. 在 root 帳號按右鍵選擇 Add host from which the user can connect
4. 將 192.168.232.108 加入
Q: 連線 MySQL 時出現 "Access denied for user 'root'@'192.168.232.108' to database 'jrsysradius'"
A:
1. 開啟 Server 上的 MySQL Administrator
2. 選擇 User Administration
3. 選擇 root 帳號所使用的 Host 名稱
4. 將要使用的 database 權限加入 Assigned Privileges
在 Mac 上安裝 Tomcat 的方法
參考網址
http://developer.apple.com/internet/java/tomcat1.html
Java and Tomcat on Mac OS X, Part I
Java and Tomcat on Mac OS X, Part II
Java and Tomcat on Mac OS X, Part I
Java and Tomcat on Mac OS X, Part II
2006年6月9日 星期五
JSP參數傳送編碼問題
當使用 POST 的方式傳送參數時大部分是不會遇到問題的,但是當您使用URL加參數(GET)傳送參數時,常常會遇到編碼的問題。以下為解決的方法:
1.
如果 tomcat 是 5.0.x 的話,在 conf/server.xml 中加入 URIEncoding="utf-8" 如下面所示:
<Connector port="8080"
maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" redirectPort="8443" acceptCount="100"
debug="0" connectionTimeout="20000"
disableUploadTimeout="true" URIEncoding="utf-8" />
2.
程式中需要使用 URL 傳送參數的地方改寫成
Server: "url.asp?var1=" + URLEncoder.encode(var1Value, "utf-8")
Client: "url.asp?var1=" + encodeURI(var1Value)
3.
接收參數頁則不需要再經過 var1Value = new String(request.getParameter("var1").getBytes("8859_1"), "UTF-8");
直接接收即可 var1Value = request.getParameter("var1");
4.
以上網頁全部為 utf-8 編碼
1.
如果 tomcat 是 5.0.x 的話,在 conf/server.xml 中加入 URIEncoding="utf-8" 如下面所示:
<Connector port="8080"
maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" redirectPort="8443" acceptCount="100"
debug="0" connectionTimeout="20000"
disableUploadTimeout="true" URIEncoding="utf-8" />
2.
程式中需要使用 URL 傳送參數的地方改寫成
Server: "url.asp?var1=" + URLEncoder.encode(var1Value, "utf-8")
Client: "url.asp?var1=" + encodeURI(var1Value)
3.
接收參數頁則不需要再經過 var1Value = new String(request.getParameter("var1").getBytes("8859_1"), "UTF-8");
直接接收即可 var1Value = request.getParameter("var1");
4.
以上網頁全部為 utf-8 編碼
2006年5月17日 星期三
將網頁focus中的物件框線拿掉
當你點選連結或正按下按鈕時,該目標物旁邊就會出現不太雅觀的虛線框
如果要拿掉的話,只要加入一段 CSS 程式碼即可
a,area { blr:expression(this.onFocus=this.blur()) } /* for IE */
:focus { -moz-outline-style: none; } /* for Firefox */
如果要拿掉的話,只要加入一段 CSS 程式碼即可
a,area { blr:expression(this.onFocus=this.blur()) } /* for IE */
:focus { -moz-outline-style: none; } /* for Firefox */
2006年4月28日 星期五
如何利用 ASP 輸出 Excel 檔案
撰寫一支asp,內容如下
<%
Response.AddHeader "Content-Disposition", "attachment; filename=機關成員名單.xls"
Response.ContentType = "application/ms-excel"
%>
<table border="1">
<tr>
<td>編號</td>
<td>姓名</td>
<td>機關名稱</td>
<td>機關代碼</td>
<td>日期1</td>
<td>日期2</td>
</tr>
<tr>
<td>1</td>
<td>小明</td>
<td>日光燈有限公司</td>
<td style="mso-number-format:\@">0012</td>
<td style="mso-number-format:yyyy\/m\/d;\@"><%=date%></td>
<td style="mso-number-format:yyyy\"\年\"m\"\月\"d\"\日\";\@"><%=date%></td>
</tr>
</table>
<%
Response.Flush
Response.Clear
%>
說明:
1. Response.ContentType 設定輸出為 Excel
2. Response.AddHeader 用來將結果輸出成檔案,「attachment;」不加的話會變成直接由瀏覽器開啟,「filename=」用來設定檔案名稱
3. Table 的表格相對應 Excel 的儲存格
4. 若要設定儲存格格式(如文字、日期格式),則在加上style屬性,並且設定mso-number-format值。
mso-number-format 的參考方式可以利用將 Excel 另存成 XML 試算表,然後用 notepad 開啟該檔案,並參考檔案中該 Cell 所設定的 Style
如: ,將「mm/dd/yy;@」套用到上面的 mso-number-format 即可。
但是特殊字元前必需加上反斜線「\」,所以正確格式為:「mm\/dd\/yy;\@」。
註: 特殊字元如:中文字、「/」、「@」、「&」...等。
參考來源: http://www.codeproject.com/aspnet/DAtaGridExportToExcel.asp
<%
Response.AddHeader "Content-Disposition", "attachment; filename=機關成員名單.xls"
Response.ContentType = "application/ms-excel"
%>
<table border="1">
<tr>
<td>編號</td>
<td>姓名</td>
<td>機關名稱</td>
<td>機關代碼</td>
<td>日期1</td>
<td>日期2</td>
</tr>
<tr>
<td>1</td>
<td>小明</td>
<td>日光燈有限公司</td>
<td style="mso-number-format:\@">0012</td>
<td style="mso-number-format:yyyy\/m\/d;\@"><%=date%></td>
<td style="mso-number-format:yyyy\"\年\"m\"\月\"d\"\日\";\@"><%=date%></td>
</tr>
</table>
<%
Response.Flush
Response.Clear
%>
說明:
1. Response.ContentType 設定輸出為 Excel
2. Response.AddHeader 用來將結果輸出成檔案,「attachment;」不加的話會變成直接由瀏覽器開啟,「filename=」用來設定檔案名稱
3. Table 的表格相對應 Excel 的儲存格
4. 若要設定儲存格格式(如文字、日期格式),則在
mso-number-format 的參考方式可以利用將 Excel 另存成 XML 試算表,然後用 notepad 開啟該檔案,並參考檔案中該 Cell 所設定的 Style
如:
但是特殊字元前必需加上反斜線「\」,所以正確格式為:「mm\/dd\/yy;\@」。
註: 特殊字元如:中文字、「/」、「@」、「&」...等。
參考來源: http://www.codeproject.com/aspnet/DAtaGridExportToExcel.asp
訂閱:
文章 (Atom)