???????Java??oracle??????????
???????????? ???????[ 2016/12/9 10:00:58 ] ????????????? Oracle JAVA
?????????????????????????JNDI:
????JNDI???????Java????????????Java Naming and Directory Interface ??JNDI?????????Java??ó????з??????????????????API??JNDI??J2EE????????????JNDI????????????????????????????????????Tomcat???????????JNDI???????????????????????Java?????API?????????????????????????????÷????仯????????????????????????????JNDI???????С?????????????????????????????
?????????????????????????J2SE??????????JNDI??J2EE????????????????bean????
???????????????????????????????Tomcat?????????JNDI???????????????????????????Tomcat??????????eclipse?????ú?Tomcat???????????????????д????????eclipse???????Tomcat???????????????context.xml?к???????????????????????£?
????<Resource
????name="jdbc/jspJNDI"
????auth="Container"
????type="javax.sql.DataSource"
????driverClassName="oracle.jdbc.driver.OracleDriver"
????url="jdbc:oracle:thin:@127.0.0.1:1521:orcl"
????username="scott"
????password="a"
????initialSize="10"
????minIdle="5"
????maxTotal="100"
????validationQuery="select 1 from dual"
????/>
??????????????????????????????????????????????????????????????name????????????????????????????name????????????????????????????
????????????дDbHleper???????
????package com.yc.commons;
????import java.sql.Connection;
????import javax.naming.Context;
????import javax.naming.InitialContext;
????import javax.sql.DataSource;
????import java.sql.SQLException;
????public class DbHelper {
????private static DataSource dataSource;
????static{
????try {
????Context context= new InitialContext();
????//java:comp/env/ ???????tomcat????????????????
????dataSource = (DataSource) context.lookup("java:comp/env/jdbc/jspJNDI");
????} catch (Exception e) {
????// TODO Auto-generated catch block
????e.printStackTrace();
????}
????}
????//???????????????
????public static Connection getConn(){
????Connection conn = null;
????if(dataSource !=null){
????try {
????conn = dataSource.getConnection(); //???????????????????
????} catch (SQLException e) {
????// TODO Auto-generated catch block
????e.printStackTrace();
????}
????}
????return conn;
????}
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11