public static DataSource getDataSource()
throws SQLException, NamingException{
if(m_ds == null){
Context ctx = null;
try{
Hashtable ht = new Hashtable();
ht.put(Context.INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory");
ht.put(Context.PROVIDER_URL,"t3://localhost:80");
ctx = new InitialContext(ht);
m_ds = (DataSource)ctx.lookup("SS3000DB");
}
catch(Exception e){
err = e.toString();
}
finally{
try {ctx.close();}
catch (Exception e) {
// a failure occurred
}
} } return m_ds;
}
throws SQLException, NamingException{
if(m_ds == null){
Context ctx = null;
try{
Hashtable ht = new Hashtable();
ht.put(Context.INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory");
ht.put(Context.PROVIDER_URL,"t3://localhost:80");
ctx = new InitialContext(ht);
m_ds = (DataSource)ctx.lookup("SS3000DB");
}
catch(Exception e){
err = e.toString();
}
finally{
try {ctx.close();}
catch (Exception e) {
// a failure occurred
}
} } return m_ds;
}
解决方案 »
- struts2文件上传生成多个临时文件
- 从国际化资源文件中取出来的中文是乱码
- 哪位大虾有thinking in java 4 的中文版给发一份
- hibernate操作数据库
- 关于Java3D
- 老是报这个错:Cannot find ActionMappings or ActionFormBeans collection 与偶人知道怎么解决么?
- Struts2.X乱码问题
- JSP中submit提交的链接是什么?
- 如何使(动态更新的新闻)标题连接滚动显示 我是用jsp+mysql写的新闻发布
- 帮我看一下这条数据库更新语句,谢谢!
- 如何在一个tomcat服务器中放两个网站?
- 急急!!!在javascript函数中调用jsp数组方法>
Context ctx=new InitialContext();
DataSource ds=(DataSource)ctx.lookup("java:comp/env/SS3000DB");
Connection conn=ds.getConnection();
Statement stm=conn.createStatement();
ResultSet rs=stm.executeQuery(sql);
..... ......... ..........
这个类找不到?怎么办?
java.sql.SQLException: ORA-00600: 内部错误代码,参数: [ttcgcshnd-1], [0], [], []
, [], [], [], []
这样调整既可:
将oracle的jdbc driver(classes12.zip)放到weblogic.jar前边,
原理:
使用jdbc时(不管在自己的应用里直接连,还是使用别人提供的连接池或是工具类),最好保证您使用的jdbc驱动的版本(最好就用你安装的数据库自带的,这样小版本也是一致的)和所连接的数据库的版本是一致的,否则有时会出一些莫名其妙的问题,白白浪费时间。 weblogic中由于对oracle数据库做了一些内置的支持,在代码中使用到了比如OracleConnection之类的oracle提供的类,所以在weblogic.jar中包含了一个oracle的老版本jdbc driver。如果用户需要使用oracle的oci或是thin driver而不是weblogic提供的jdriver for oracle,则需要修改weblogic启动脚本,将oracle的jdbc driver(classes12.zip)放到weblogic.jar前边。
<%@page import="java.sql.*,javax.naming.Context,javax.naming.InitialContext"%>
<%@page import="javax.sql.DataSource"%>
就可以了