0、数据源的配置
http://localhost:8080/admin声称数据源好像不起什么作用
运行时产生
D:\Documents and Settings\zpt\jbproject\untitled3\Tomcat\conf\server8080.xml文件
手工编辑其,去掉第二行的注释,并加入使其为:
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引用中
其它参见idea 4.5 使用 tomcat 4
http://localhost:8080/admin声称数据源好像不起什么作用
运行时产生
D:\Documents and Settings\zpt\jbproject\untitled3\Tomcat\conf\server8080.xml文件
手工编辑其,去掉第二行的注释,并加入使其为:
<?xml version="1.0" encoding="UTF-8"?>
<Server debug="0" port="8081" shutdown="SHUTDOWN">
<Service name="Catalina">
<Connector acceptCount="10" connectionTimeout="60000" debug="0" maxThreads="75" minSpareThreads="5" port="8080"/>
<Engine debug="0" defaultHost="localhost" name="Catalina">
<Host appBase="D:\Documents and Settings\zpt\jbproject\untitled3\Tomcat\webapps" autoDeploy="false" debug="0" deployXML="false" name="localhost" unpackWARs="false">
<Context workDir="D:\Documents and Settings\zpt\jbproject\untitled3\Tomcat\work\WebModule1" path="/WebModule1" displayName="WebModule1" docBase="D:/Documents and Settings/zpt/jbproject/untitled3/WebModule1" reloadable="true">
<Resource type="javax.sql.DataSource" name="jdbc/oracle"/>
<ResourceParams name="jdbc/oracle">
<parameter>
<name>maxWait</name>
<value>5000</value>
</parameter>
<parameter>
<name>maxActive</name>
<value>4</value>
</parameter>
<parameter>
<name>password</name>
<value>pmiswh</value>
</parameter>
<parameter>
<name>url</name>
<value>jdbc:oracle:thin:@10.161.160.10:1521:lydyj</value>
</parameter>
<parameter>
<name>driverClassName</name>
<value>oracle.jdbc.driver.OracleDriver</value>
</parameter>
<parameter>
<name>maxIdle</name>
<value>2</value>
</parameter>
<parameter>
<name>username</name>
<value>pmis</value>
</parameter>
</ResourceParams>
</Context>
</Host>
</Engine>
</Service>
</Server>
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<list.size();; i++);{
str+=((Cat);list.get(i););.getName();;
}
HibernateUtil.closeSession();;
}
public void o4(); throws Exception{
Session sess = HibernateUtil.currentSession();;
Cat obj=(Cat);sess.get(Cat.class, new Long(2148););;
obj.setMesString(obj.getMes();.getSubString(1, (int);obj.getMes();.length();););;
obj.setMesString("成郁落叶沉郁落叶沉鱼落雁沉鱼落雁");;
Transaction tx = sess.beginTransaction();;
obj.setMes(Hibernate.createClob(" "););;
sess.save(obj);;
sess.flush();;
sess.refresh(obj, LockMode.UPGRADE);;
CLOB clob = (CLOB); obj.getMes();;
Writer pw = clob.getCharacterOutputStream();;
pw.write(obj.getMesString(););;
pw.flush();;
pw.close();;
sess.flush();;
tx.commit();;
HibernateUtil.closeSession();;
}
public void s1(); throws Exception {
Class.forName("com.sybase.jdbc2.jdbc.SybDriver");.getInterfaces();;
String url = "jdbc:sybase:Tds:10.161.160.10:4100";
Connection conn = DriverManager.getConnection(url, "pmiswh", "pmiswh");;
conn.setCatalog("rlzy2");;
Statement stmt = conn.createStatement();;
ResultSet rs = stmt.executeQuery("select xm from t_zgxx");;
str = "";
while (rs.next();); {
str += this.native2Unicode(rs.getString("xm"););;
}
rs.close();;
stmt.close();;
conn.close();;
}
public void s2(); throws Exception {
Context iniContext = new InitialContext();;
Context envContext = (Context); iniContext.lookup("java:comp/env");;
DataSource ds = (DataSource); envContext.lookup("jdbc/pmis/sybase");;
Connection conn = ds.getConnection();;
conn.setCatalog("rlzy2");;
Statement stmt = conn.createStatement();;
ResultSet rs = stmt.executeQuery("select xm from t_zgxx");;
str = "";
while (rs.next();); {
str += this.native2Unicode(rs.getString("xm"););;
}
rs.close();;
stmt.close();;
conn.close();;
}
private void jbInit(); throws Exception {
}
public String native2Unicode(String s); {
if (s == null); {
return null;
}
byte[] buffer = new byte[s.length();];
for (int i = 0; i < s.length();; i++); {
buffer[i] = (byte); s.charAt(i);;
}
return new String(buffer);;
}
}
其它参见idea 4.5 使用 tomcat 4