English 中文(简体)
• 如何在不使用服务器/垃圾时了解情况? 只有普通类档案
原标题:How to get Context when servlet/jsp is not used? Only plain class files

My existing web application gets database pooling parameters from context. Now, I m developing a new web service to be deployed as a separate application, but using the previous database.

在这项新的网络服务申请中,我没有使用任何服务器和联合项目。 他们只是一个服务班子。 在这种情况下,我如何获得背景参数?

在早先的Im使用服务器的情况下,我的情况如下:

<?xml version="1.0" encoding="UTF-8"?>
<Context antiResourceLocking="false" privileged="true" >
 <Resource 
    name="jdbc/NetmarketDB"
    auth="Container"
    type="javax.sql.DataSource"
    removeAbandoned="true"
    removeAbandonedTimeout="30"
    maxActive="100"
    maxIdle="30"
    maxWait="1000"
    username="root"
    password="xxxxxxxx"
    driverClassName="com.mysql.jdbc.Driver"
    url="jdbc:mysql://localhost:3306/netmarket"/>
</Context>

......和我从一个服务器或共同财产调查中获得以下背景:

Connection conn = MySqlDB.getDBConnection(getServletContext());

但现在我不使用任何电灯/JSP,我感到困惑。 请帮助我。

最佳回答

即便在您的网络应用中,在您的问询中,如果你掌握了资源定义,那么你就能够利用日本国际开发公司:

Context ctx = new InitialContext();
DataSource ds = (DataSource)ctx.lookup("jdbc/NetmarketDB");
Connection con = ds.getConnection("root", "xxxxxxxx");

如果你没有在网上申请中运行,那么:

Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/netmarket", root", "xxxxxxxx");
问题回答

暂无回答




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签