<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName"
value="com.mysql.jdbc.Driver"><!-- com.microsoft.sqlserver.jdbc.SQLServerDriver -->
</property>
<property name="url"
value="jdbc:mysql://127.0.0.1:3306/bims"><!-- jdbc:sqlserver://127.0.0.1:1433;databaseName=wootion -->
</property>
<property name="username" value="root"></property>
<property name="password" value="123"></property>
</bean>
</beans>
我要读取url username password Java读取该怎么写 自己写的太繁琐 大家指点下
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName"
value="com.mysql.jdbc.Driver"><!-- com.microsoft.sqlserver.jdbc.SQLServerDriver -->
</property>
<property name="url"
value="jdbc:mysql://127.0.0.1:3306/bims"><!-- jdbc:sqlserver://127.0.0.1:1433;databaseName=wootion -->
</property>
<property name="username" value="root"></property>
<property name="password" value="123"></property>
</bean>
</beans>
我要读取url username password Java读取该怎么写 自己写的太繁琐 大家指点下
解决方案 »
- 用的是ssh框架,想把显示在jsp页面上的从数据库查询出来的数据导出生成excel
- maven 使用项目中web-inf/lib 中的jar包
- 请问怎么将bean里面对数据库操作的查询结果返回给servlet?
- 我都哭了,帮帮我吧resultSet = statement.executeQuery(test);问题
- 关于JSP的超链接问题
- 大家用htmlparser提取文本内容时 有没有出现内存溢出呀
- 求教用jxl解析excel时候小数被自动截取的问题
- 关于页面导出excel数据格式问题
- 请问一下大家有没有碰到过这种java报错..The method _$1(ResultSet, PageCtrl) is ambiguous for the type DBUtil
- jsp连接MYSQL的问题?在线等待!急#
- 为了健康,别做这19件事!!!!切记
- Struts中select 标签问题
干嘛要自己费劲读啊?
看看这个吧应该适合!http://edu.codepub.com/2010/0108/19503.php
你先根据XML结构定义好对应的bean, 然后用DOM4J 或JDOM 或 ...... ,有很多工具的。 easy啦。
不会的话,网上一搜一大把的
File file = new File("C:\\test.xml");
SAXReader reader = new SAXReader();
Document doc = reader.read(file);
Map xmlMap = new HashMap();
xmlMap.put("nSpace", "http://www.springframework.org/schema/beans");
XPath x = doc.createXPath("//nSpace:property");
x.setNamespaceURIs(xmlMap);
List list = x.selectNodes(doc); for(int i = 0; i < list.size(); i++){
Element e = (Element)list.get(i);
System.out.println(e.attributeValue("name") + " : " + e.attributeValue("value"));
}结果:
driverClassName : com.mysql.jdbc.Driver
url : jdbc:mysql://127.0.0.1:3306/bims
username : root
password : 123比较麻烦的地方是名字空间的处理
Node node = doc.selectSingleNode("//*[@name='url']");
Element e = (Element)node;
System.out.println(e.attributeValue("name") + " : " + e.attributeValue("value"));
node = doc.selectSingleNode("//*[@name='username']");
e = (Element)node;
System.out.println(e.attributeValue("name") + " : " + e.attributeValue("value")); node = doc.selectSingleNode("//*[@name='password']");
e = (Element)node;
System.out.println(e.attributeValue("name") + " : " + e.attributeValue("value"));