Java版 - 请高手指教:Tomcat JNDI problem |
|
|
|
|
|
n*******d 发帖数: 4 | 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 | l******u 发帖数: 10 | 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. | l******u 发帖数: 10 | 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. | m**c 发帖数: 90 | 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
|
|
|
|
|
|
|