Hivemind连数据库(示例)

hivemodule.xml
<?xml version="1.0"?>
<module id="Snail" version="4.0.0">
	<contribution
		configuration-id="tapestry.state.ApplicationObjects">
		<state-object name="user" scope="session">
			<create-instance class="com.neusoft.snail.User" />
		</state-object>
	</contribution>
	<service-point id="DataSource" interface="javax.sql.DataSource">
		<invoke-factory model="singleton">
			<construct
				class="org.apache.commons.dbcp.BasicDataSource">
				<set property="driverClassName"
					value="sun.jdbc.odbc.JdbcOdbcDriver" />
				<set property="url"
					value="jdbc:odbc:snail" />
				<set property="username" value="" />
				<set property="password" value="" />
				<set property="defaultAutoCommit" value="false" />
				<set property="maxActive" value="20" />
				<set property="initialSize" value="2" />
			</construct>
		</invoke-factory>
	</service-point>
</module>


DataBean.java
Registry registry = org.apache.hivemind.impl.RegistryBuilder
					.constructDefaultRegistry();
			DataSource dataSource = (DataSource) registry.getService(
					"Snail.DataSource", javax.sql.DataSource.class);
			conn = dataSource.getConnection();

你可能感兴趣的:(java,apache,sql,xml)