http://localhost:8080/admin声称数据源好像不起什么作用
运行时产生
D:\Documents and Settings\zpt\jbproject\untitled3\Tomcat\conf\server8080.xml文件
手工编辑其,去掉第二行的注释,并加入使其为:
maxWait 5000 maxActive 4 password pmiswh url jdbc:oracle:thin:@10.161.160.10:1521:lydyj driverClassName oracle.jdbc.driver.OracleDriver maxIdle 2 username pmis
1、Hibernate
a、拷贝ojdbc14.jar、jcconn2d.jar到tomcat 5.0\common\lib目录下,
并添加到jbuilder的JDKS的Class引用中
b、拷贝
cglib-full-2.0.1.jar
commons-collections-2.1.jar
commons-lang-1.0.1.jar
commons-logging-1.0.3.jar
dom4j-1.4.jar
ehcache-0.7.jar
hibern8ide.jar
hibernate2.jar
hibernate-tools.jar
jdom.jar
jta.jar
odmg-3.0.jar
oscache-2.0.jar
到tomcat 5.0\common\lib目录下,
并添加到jbuilder的Servlet的Class引用中
package p; import net.sf.hibernate.*; import net.sf.hibernate.cfg.*; public class HibernateUtil { private static final SessionFactory sessionFactory; static { try { sessionFactory = new Configuration();.configure(new HibernateUtil();.getClass();.getResource("/hibernate.cfg.xml"););.buildSessionFactory();; } catch (HibernateException ex); { throw new RuntimeException("Exception building SessionFactory: " + ex.getMessage();, ex);; } } public static final ThreadLocal session = new ThreadLocal();; public static Session currentSession(); throws HibernateException { Session s = (Session); session.get();; // Open a new Session, if this Thread has none yet //if (s == null); { s = sessionFactory.openSession();; session.set(s);; } return s; } public static void closeSession(); throws HibernateException { Session s = (Session); session.get();; session.set(null);; if (s != null); { s.close();; } } } package web; import p.DB; import java.sql.ResultSet; import javax.naming.Context; import javax.naming.InitialContext; import javax.sql.DataSource; import java.sql.Connection; import java.sql.Statement; import java.sql.DriverManager; import net.sf.hibernate.Session; import p.HibernateUtil; import net.sf.hibernate.Query; import java.util.List; import hibernates.Cat; import net.sf.hibernate.LockMode; import net.sf.hibernate.Transaction; import oracle.sql.CLOB; import java.io.Writer; import net.sf.hibernate.Hibernate; public class test { private String str; public String getStr(); { return str; } public void setStr(String str); { this.str = str; } public test(); throws Exception { try { jbInit();; } catch (Exception ex); { ex.printStackTrace();; } } public void o1(); throws Exception { Class.forName("oracle.jdbc.driver.OracleDriver");.getInterfaces();; String url = "jdbc:oracle:thin:@10.161.160.10:1521:lydyj"; Connection conn = DriverManager.getConnection(url, "pmis", "pmiswh");; Statement stmt = conn.createStatement();; ResultSet rs = stmt.executeQuery("select name from cat");; str = ""; while (rs.next();); { str += rs.getString("name");; } rs.close();; stmt.close();; conn.close();; } public void o2(); throws Exception { Context iniContext = new InitialContext();; Context envContext = (Context); iniContext.lookup("java:comp/env");; DataSource ds = (DataSource); envContext.lookup("jdbc/pmis/oracle");; Connection conn = ds.getConnection();; Statement stmt = conn.createStatement();; ResultSet rs = stmt.executeQuery("select name from Cat");; str = ""; while (rs.next();); { str += rs.getString("name");; } rs.close();; stmt.close();; conn.close();; } public void o3(); throws Exception{ Session sess=HibernateUtil.currentSession();; Query query=sess.createQuery("from Cat");; List list=query.list();; str=""; for(int i=0; i
其它参见idea 4.5 使用 tomcat 4