2015年4月20日 星期一

Java - Oracle 連線使用 tnsname

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

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.

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.

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.

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 就可以了

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;
    }
}