Redian新闻
>
请高手指教:Tomcat JNDI problem
avatar
请高手指教:Tomcat JNDI problem# Java - 爪哇娇娃
n*d
1
折腾了二个星期了 :(
Tomcat 4.0 on Linux, trying to connect to MySQL
It can't find the data source I defined and throws this error:
javax.servlet.ServletException: Cannot create resource instance
I'm not sure if there's any security setting preventig this?
I can access MySQL using the following jsp code:
Class.forName("org.gjt.mm.mysql.Driver");
Connection dbcon = DriverManager.getConnection(loginUrl,
loginUser, loginPasswd);
Statement statement = dbcon.createSta
avatar
l*u
2
I didn't see you define the JNDI name for the datasource anywhere is the xml
descriptor. JNDI is a globally accessible infrastructure. The entry you
defined in the web.xml is a resource reference, which should be mapped into
JNDI entry in server specific deployment descriptor (i.e, weblogic.xml).
Anyhow, make sure your have a datasource defined in Tomcat with the correct
JNDI name. You should be able to see the entry on Tomcat Admin Console.
avatar
l*u
3
If you defined the JNDI name for the datasource on Tomcat platform, you don't
even need to declare a corresponding resource-ref in your web.xml file. Your
jndi lookup code should be able to locate the datasource directly.
avatar
m*c
4

Tomcat is a little bit tricky to setup DNS. Your server.xml settings are
correct. You don't need any settings in web.xml. The tricky part is how you
get hold of DataSource object via JNDI (Tomcat does thing differently than
other app servers such as WebLogic, WebSphere, etc.). Here is a sample code
to retrieve DataSource object vai JDNI:
InitialContext context = new InitialContext();
Context envContext = (Context)context.lookup("java:comp/env");
DataSource dataSource = (DataSour

【在 n*******d 的大作中提到】
: 折腾了二个星期了 :(
: Tomcat 4.0 on Linux, trying to connect to MySQL
: It can't find the data source I defined and throws this error:
: javax.servlet.ServletException: Cannot create resource instance
: I'm not sure if there's any security setting preventig this?
: I can access MySQL using the following jsp code:
: Class.forName("org.gjt.mm.mysql.Driver");
: Connection dbcon = DriverManager.getConnection(loginUrl,
: loginUser, loginPasswd);
: Statement statement = dbcon.createSta

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。