Hibernate3 jndi 配置

发布时间:2016-12-11 8:18:23 编辑:www.fx114.net 分享查询网我要评论
本篇文章主要介绍了"Hibernate3 jndi 配置",主要涉及到Hibernate3 jndi 配置方面的内容,对于Hibernate3 jndi 配置感兴趣的同学可以参考一下。

1、配置tomact DataSource(apache-tomcat-5.5.20)      在server.xml中添加            <Host          appBase="webapps"          name="localhost">          <Context path="/wapcp" docBase="wapcp"  debug="5" reloadable="true" crossContext="true">        <Resource name="jdbc/wapcp" auth="Container"          type="javax.sql.DataSource" driverClassName="oracle.jdbc.driver.OracleDriver"          url="jdbc:oracle:thin:@192.168.1.245:1521:orcl"          username="Wap100" password="wap100" maxActive="20" maxIdle="10" maxWait="-1"/>        </Context>      </Host> 2、写个servlet测试DataSource     public class Test { public ResultSet connect(){  try{  Context ctx = new InitialContext();  if(ctx==null)   throw new Exception("no context");  DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/wapcp");  if(ds!=null){   Connection  conn = ds.getConnection();   Statement st = conn.createStatement();   ResultSet  rs=st.executeQuery("select * from WAP_D_USER");   return rs;     }  }catch(Exception e){   e.printStackTrace();  }  return null; } public static void main(String args []){  Test ts = new Test();  ts.connect(); }} servlet: public void doGet(HttpServletRequest request, HttpServletResponse response)   throws ServletException, IOException {   response.setContentType("text/html");  PrintWriter out = response.getWriter();  Test tss = new Test();  ResultSet rs =tss.connect();   out    .println("<!DOCTYPE HTML PUBLIC /"-//W3C//DTD HTML 4.01 Transitional//EN/">");  out.println("<HTML>");  out.println("  <HEAD><TITLE>A Servlet</TITLE></HEAD>");  out.println("  <BODY>");  try{   while(rs.next()){    out.print(rs.getString(1));   }  }catch(Exception e){   e.printStackTrace();  }  out.print(this.getClass());  out.println(", using the GET method");  out.println("  </BODY>");  out.println("</HTML>");  out.flush();  out.close(); } 3、配置hibernate.cfg.xml    <property name="hibernate.show_sql">True</property> <property name="connection.datasource">  java:comp/env/jdbc/wapcp </property> <property name="dialect">  org.hibernate.dialect.Oracle9Dialect </property>    

上一篇:我苦难的旅游
下一篇:鸡毛信客户端的删除

相关文章

相关评论