Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
Tags
- vscode
- ssh
- web.xml
- Windows
- Mac
- grep
- 단축키
- 줄바꿈 문자
- Quartz
- Source
- lsof
- xargs
- resource
- tomcat
- import
- context
- VirtualBox
- plugin
- netsh
- profile
- Windows 10
- port
- GIT
- Eclipse
- maVen
- 네트워크
- bash
- find
- IntelliJ
- JavaScript
Archives
- Today
- Total
develog
jndi test 2 본문
commons-dbcp-1.4.jar
commons-pool-1.6.jar
fscontext-4.4.jar
ojdbc14.jar
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.naming.Reference;
import javax.naming.StringRefAddr;
import javax.sql.DataSource;
public class TestJndi {
public static void main(String[] args) throws Exception {
System.out.println("START");
System.out.println("-------------------------------------------");
TestJndi main = new TestJndi();
main.setUpJndi();
main.testJndi();
System.out.println("-------------------------------------------");
System.out.println("END");
}
public void testJndi() throws Exception {
InitialContext ic = new InitialContext();
DataSource ds = null;
ds = (DataSource) ic.lookup("jdbc/oracle");
System.out.println(ds.getConnection());
ds = (DataSource) ic.lookup("jdbc/mysql");
System.out.println(ds.getConnection());
}
public void setUpJndi() throws Exception {
setUpJndiTemplate("jdbc/oracle", "oracle.jdbc.driver.OracleDriver", "jdbc:oracle:thin:@127.0.0.1:1521:ORCL",
"scott", "tiger");
setUpJndiTemplate("jdbc/mysql", "com.mysql.jdbc.Driver", "jdbc:mysql://127.0.0.1/myDbSchema", "scott", "tiger");
}
private void setUpJndiTemplate(String jndiName, String driverClassName, String url, String username, String password) throws NamingException {
System.setProperty(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.RefFSContextFactory");
Reference ref = new Reference("javax.sql.DataSource", "org.apache.commons.dbcp.BasicDataSourceFactory", null);
ref.add(new StringRefAddr("driverClassName", driverClassName));
ref.add(new StringRefAddr("url", url));
ref.add(new StringRefAddr("username", username));
ref.add(new StringRefAddr("password", password));
InitialContext ic = new InitialContext();
ic.rebind(jndiName, ref);
}
}
package test; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; import javax.naming.Reference; import javax.naming.StringRefAddr; import javax.sql.DataSource; public class TestJndi { public static void main(String[] args) throws Exception { System.out.println("START"); System.out.println("-------------------------------------------"); TestJndi main = new TestJndi(); main.setUpJndi(); main.testJndi(); System.out.println("-------------------------------------------"); System.out.println("END"); } public void testJndi() throws Exception { InitialContext ic = new InitialContext(); DataSource ds = null; ds = (DataSource) ic.lookup("jdbc/oracle"); System.out.println(ds.getConnection()); ds = (DataSource) ic.lookup("jdbc/mysql"); System.out.println(ds.getConnection()); } public void setUpJndi() throws Exception { setUpJndiTemplate("jdbc/oracle", "oracle.jdbc.driver.OracleDriver", "jdbc:oracle:thin:@127.0.0.1:1521:ORCL", "scott", "tiger"); setUpJndiTemplate("jdbc/mysql", "com.mysql.jdbc.Driver", "jdbc:mysql://127.0.0.1/myDbSchema", "scott", "tiger"); } private void setUpJndiTemplate(String jndiName, String driverClassName, String url, String username, String password) throws NamingException { System.setProperty(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.RefFSContextFactory"); Reference ref = new Reference("javax.sql.DataSource", "org.apache.commons.dbcp.BasicDataSourceFactory", null); ref.add(new StringRefAddr("driverClassName", driverClassName)); ref.add(new StringRefAddr("url", url)); ref.add(new StringRefAddr("username", username)); ref.add(new StringRefAddr("password", password)); InitialContext ic = new InitialContext(); ic.rebind(jndiName, ref); } }
'Dev > Java' 카테고리의 다른 글
Spring 테스트 Log4j 초기화 (0) | 2013.12.11 |
---|---|
Quartz test (0) | 2013.12.11 |
applicationContext.xml, sqlMapConfig, configLocation (classpath or file) (0) | 2013.12.09 |
@ContextConfiguration (0) | 2013.12.09 |
tail (0) | 2013.12.05 |
Comments