Background Description
Work client code does not alter session set nls_date_format = 'YYYY-MM-DD HH24:MI:SS'
, this sql, but the agent caught an average of 60 requests per second, the user "to a statement"
weblogic using JNDI
Self-configuring
pull down here there is a test of table names need to pay attention to the next, there may be a relationship with the following error, you can not make oracl keyword ORA
Just click on the new
pull-down following a high-level opening the
fill sql, and click Save below the
target, hit the server, and save. If the point here is not being given, following a record, if you save when there is an error, the following are also recorded, do not worry, read on.
Test code
demo1 (I use this a success)
package com.leesin;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class Jndi_test {
public static void main(String[] args) {
Connection conn = null;
try {
Context ctx = new InitialContext();
//tomcat连接池
//DataSource ds=(DataSource)ctx.lookup("java:comp/env/mysql55");
//weblogic连接池
//lookup后面的是jndi的名字,在weblogic中进行配置
//必须和上面配置的一致。
DataSource ds = (DataSource) ctx.lookup("leesin");
conn = ds.getConnection();
Statement stmt6 = conn.createStatement();//创建一个Statement对象
String sql7 = "SELECT * FROM student";//生成一条sql语句
ResultSet rs17 = stmt6.executeQuery(sql7);//执行查询,把查询结果赋值给结果集对象
System.out.println("编号 \t 姓名 \t 工资 -------statment");
while (rs17.next()) {
System.out.println(rs17.getString(1) + "\t" + rs17.getString(2) + "\t" + rs17.getString(3));
}
} catch (NamingException e) {
e.printStackTrace();
} catch (
SQLException e) {
e.printStackTrace();
}
}
}
The following demo2, private final static String PROVIDER_URL = "t3: //10.0.2.90: 7001"; this sentence, there is no problem here dmeo1 may default localhost, because to be deployed to run on weblogic.
demo2
package com.leesin;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Properties;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.sql.DataSource;
public class WebLogicJndiUtil {
//初始化上下文需要用到的工厂类
private final static String INITIAL_CONTEXT_FACTORY = "weblogic.jndi.WLInitialContextFactory";
//WebLogic服务器的访问地址
private final static String PROVIDER_URL = "t3://10.0.2.90:7001";
//WebLogic服务器中的JNDI数据源名称
// private final static String ORACLE_JNDI_NAME = "JNDI/OracleDataSource";
private final static String ORACLE_JNDI_NAME = "leesin";
private final static String MYSQL_JNDI_NAME = "JNDI/MysqlDataSource";
//存储从JNDI容器中取出来的数据源
private static DataSource dsOracle = null;
private static DataSource dsMySQL = null;
static {
try {
//初始化WebLogic Server的JNDI上下文信息
Context context = getInitialContext();
//获取数据源对象
dsOracle = (DataSource) context.lookup(ORACLE_JNDI_NAME);
dsMySQL = (DataSource) context.lookup(MYSQL_JNDI_NAME);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* MethodName: getInitialContext
* Description: 获得WebLogic ServerJNDI初始上下文信息
*
* @return
* @throws Exception
* @author xudp
*/
private static Context getInitialContext() throws Exception {
Properties properties = new Properties();
properties.put(Context.INITIAL_CONTEXT_FACTORY, INITIAL_CONTEXT_FACTORY);
properties.put(Context.PROVIDER_URL, PROVIDER_URL);
return new InitialContext(properties);
}
/**
* MethodName: getOracleConnection
* Description: 获取Oracle数据库连接
*
* @return
* @throws SQLException
* @author xudp
*/
public static Connection getOracleConnection() throws SQLException {
return dsOracle.getConnection();
}
/**
* MethodName: getMySQLConnection
* Description: 获取MySQL数据库连接
*
* @return
* @throws SQLException
* @author xudp
*/
public static Connection getMySQLConnection() throws SQLException {
return dsMySQL.getConnection();
}
}
Then getOracleConnection method call this class to get connection.
报错 javax.naming.NameNotFoundException: Unable to resolve ‘leesin’. Resolved ‘’; remaining name ‘leesin’
<2019-8-20 下午06时09分55秒 CST> <Warning> <netuix> <BEA-423420> <Redirect is executed in begin or refresh action. Redirect url is /console/console.portal?_nfpb=true&_pageLabel=JdbcDatasourcesJDBCDataSourceConfigTabPage&JdbcDatasourcesJDBCDataSourceConfigPortlethandle=com.bea.console.handles.JMXHandle%28%22com.bea%3AName%3Dleesin%2CType%3Dweblogic.j2ee.descriptor.wl.JDBCDataSourceBean%2CParent%3D%5Bbase_domain%5D%2FJDBCSystemResources%5Bleesin%5D%2CPath%3DJDBCResource%5Bleesin%5D%22%29.>
javax.naming.NameNotFoundException: Unable to resolve 'leesin'. Resolved ''; remaining name 'leesin'
at weblogic.jndi.internal.BasicNamingNode.newNameNotFoundException(BasicNamingNode.java:1139)
at weblogic.jndi.internal.BasicNamingNode.lookupHere(BasicNamingNode.java:252)
at weblogic.jndi.internal.ServerNamingNode.lookupHere(ServerNamingNode.java:182)
at weblogic.jndi.internal.BasicNamingNode.lookup(BasicNamingNode.java:206)
at weblogic.jndi.internal.WLEventContextImpl.lookup(WLEventContextImpl.java:254)
at weblogic.jndi.internal.WLContextImpl.lookup(WLContextImpl.java:412)
at javax.naming.InitialContext.lookup(InitialContext.java:417)
at com.leesin.WebLogicJndiUtil.<clinit>(WebLogicJndiUtil.java:29)
at com.leesin.Jndi_test.main(Jndi_test.java:23)
at com.leesin.Servlet.doGet(Servlet.java:39)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:301)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:184)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3732)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3696)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)
at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2273)
at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2179)
at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1490)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:256)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:221)
Solution:
In Weblogic data source management
JDBC Data Source-0 set
set target option
will be checked on the service, such as the default: AdminServer
to save;
will be reported the following error
java.sql.SQLSyntaxErrorException: ORA-00903: 表名无效
What this means is ORA-00903 is the oracle of keywords, you can not use my demo does not use ah, recall, when I was a connection pool, add an initialization sql, it will not be the reason it?
Of course, I have recorded above, you may also have to do with that.
And later for a weblogic on it, it may be the version of the problem.
After the success can be connected.
Article:
https://blog.csdn.net/wx5040257/article/details/77926540
https://blog.csdn.net/weixin_37264997/article/details/84820316
https://blog.csdn.net/acmman/article/ details / 70146603