spring链接配置即可。
一、<dependencyManagement>
<dependencies>
<!-- 使用spring的BOM管理依赖 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>4.2.6.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
二、<!-- spring配置开始 --><dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- spring配置结束 -->
三、在web工程的src/main/resources/META-INF目录下添加dispatcher.xml文件,并添加如下配置:
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
可以做一个类库,用xml调用using
System.Data.Sqlcolint
using
System.Xml
咨询通过读取xml文件连接sqlserver数据库的问题
悬赏分:20
-
提问时间2007-11-6
16:34
我的问题:
1。连接数据库方式是个类库(做成dll文件)
2。连接数据库的登录名密码等字符串是从config.xml中读取
3。是从类库中读取还是从别的地方读取config.xml?因为在类库中有个连接数据库的语句。
4。如果连接数据库的密码错误,会自动提示连接错误,然后d出个小窗口,修改config.xml中的数据库密码等,然后保存。这个步骤在哪里写?
===================================================================================================================
我的部分代码:
1。连接数据库的类库:
Imports
System.data.sqlclient
Public
Class
DB
'sCon为连接字符串
Private
sCon
As
String
=
"User
ID=saInitial
Catalog=dbnameData
Source=(local)
"
Public
Function
GetDataTable(ByVal
strSql
As
String)
As
DataTable
Dim
myDt
As
New
DataTable
Dim
sqlConn
As
SqlConnection
=
New
SqlConnection(sCon)
Dim
myCmd
As
SqlCommand
=
New
SqlCommand(strSql,
sqlConn)
Dim
myDa
As
New
SqlDataAdapter(strSql,
sqlConn)
Try
myDa.Fill(myDt)
Catch
er
As
Exception
Finally
sqlConn.Close()
End
Try
Return
myDt
End
Function
End
Class
public
Void
ReaderXML(string
URL)//URL是XML文件的路径
{
DataSet
ds
=
new
DataSet()
ds.ReaderXml("URL")
//下面就是把这个数据集存到数据库里面
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)