当前位置:首页 » 操作系统 » 连接数据库的配置文件

连接数据库的配置文件

发布时间: 2022-08-27 20:14:42

❶ Spring配置文件中怎么配置数据库连接

xml配置文件中配置如下:
java代码 收藏代码
<spring:bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<spring:property name="locations">
<spring:list>
<spring:value>classpath:conf/jdbc.properties</spring:value>
</spring:list>
</spring:property>
</spring:bean>
<spring:bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<spring:property name="driverClassName"
value="${jdbc.driverClassName}" />
<spring:property name="url"
value="${jdbc.url}" />
<spring:property name="username" value="${jdbc.username}" />
<spring:property name="password" value="${jdbc.password}" />
<spring:property name="maxActive" value="30" />
<spring:property name="maxIdle" value="10" />
<spring:property name="maxWait" value="1000" />
<spring:property name="defaultAutoCommit" value="true" />
</spring:bean>
jdbc.properties配置文件中连接数据库配置:
Java代码 收藏代码
#sqlserver数据源配置
jdbc.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver
jdbc.url=jdbc:sqlserver://192.168.1.60:1408;DatabaseName=test
jdbc.username=sa
jdbc.password=1
#mysql数据源配置
jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://192.168.1.60:3306/test
jdbc.username=root
jdbc.password=root
#Oracle数据源配置
jdbc.driverClassName=oracle.jdbc.driver.OracleDriver
jdbc.url=jdbc:oracle:thin:@10.60.17.9:1521:orcl
jdbc.username=admin
jdbc.password=admin

❷ 连接两个数据库 spring配置文件怎么配置

这位朋友,根据您的问题解答如下,如有不明之处可以继续补充:
你在web.xml里这么配置没问题啊,我加载两个spring的配置文件都是用逗号分割的,这个逗号是半角的,不是全角的。一般都是配置多个,放一个,services放一个。

❸ C#连接oracle数据库Add.config配置文件怎么写

C#连接Oracle数据库(查询数据)

using System;
using System.Collections.Generic;
using System.ComponentModel;
//这行和下一行都要先在引用中填加system.data.oracleclient
using System.Data.OracleClient;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
#region 从region到endregion是手工写的。别的都是系统自动生成的
//定义连接数据库的字符串
string constring = "data source=wzd;user=wzd;password=wzd;";
//进行连接
OracleConnection conn = new OracleConnection(constring);
try
{
conn.Open();//打开指定的连接
OracleCommand com = conn.CreateCommand();
//写好想执行的Sql语句
com.CommandText =
"select name from mytable where card_no='0000000002'";
OracleDataReader odr = com.ExecuteReader();
//读取数据,如果返回为false的话,就说明到记录集的尾部了
while (odr.Read())
{
//将读取到的值显示到定义的控件中。
this.lbl.Text = odr.GetOracleString(0).ToString();
}
odr.Close();//关闭reader.这是一定要写的
}
catch
{
MessageBox.Show("erro");//如果发生异常,则提示出错
}
finally
{
conn.Close();//关闭打开的连接
}

#endregion
}
}
}

C#中与Oracle连接的代码

注意:一定要添加这个:

项目->添加引用->.NET->System.Data.OracleClient.dll

using System;
using System.Data;
using System.Windows.Forms;
using System.Data.OracleClient;

namespace Test
{
/// <summary>
/// 简洁期间,直接将实现写在构造函数中
/// </summary>
public class Test
{
public Test()
{
//
// TODO: 在此处添加构造函数逻辑
//

string ConnectionString =
"Data Source=LiPu; User Id=SCOTT; Password=scott";

//连接字符串,Data Source 是指数据库名字.如我用的是本机的Oracle
//的数据库,名字为LiPu. user id 是

//用户名,你可以用System 或是你自己添加的一个用户.Password是
//对应用户的密码.

//创建一个新连接
OracleConnection conn = new OracleConnection(ConnectionString);

try
{
conn.Open(); //打开连接
OracleCommand cmd = conn.CreateCommand();

cmd.CommandText = "select * from emp"; //SQL语句
OracleDataReader rs = cmd.ExecuteReader();
//读取数据,如果rs.Read()返回为false的话,就说明到记录集的尾部了
while(rs.Read())
{
MessageBox.Show(rs.GetString(1));
}

rs.Close();
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
finally
{
conn.Close();
}
}
}
}

C#连接Oracle数据库(更改数据库中的记录并查询更改后的数据)

using System;
using System.Collections.Generic;
//这行和下一行都要先在引用中填加system.data.oracleclient
using System.ComponentModel;
using System.Data.OracleClient;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
#region 从region到endregion是手工写的。别的都是系统自动生成的
//定义连接数据库的字符串
string constring = "data source=wzd;user=wzd;password=wzd;";
//进行连接
OracleConnection conn = new OracleConnection(constring);
try
{
conn.Open();//打开指定的连接
OracleCommand com = conn.CreateCommand();
com.CommandText =
"select name from fin_ipr_inmaininfo where card_no="+
"'0000000002'";//写好想执行的Sql语句
OracleDataReader odr = com.ExecuteReader();
//读取数据,如果返回为false的话,就说明到记录集的尾部了
while (odr.Read())
{
//将读取到的值显示到定义的控件中。
this.lbl.Text = odr.GetOracleString(0).ToString();
}
odr.Close();//关闭reader.这是一定要写的
}
catch
{
MessageBox.Show("erro");//如果发生异常,则提示出错
}
finally
{
conn.Close();//关闭打开的连接
}

#endregion
}

private void button2_Click(object sender, EventArgs e)
{
#region 从region到endregion是手工写的。别的都是系统自动生成的
//定义连接数据库的字符串
string constring = "data source=wzd;user=wzd;password=wzd;";
//进行连接
OracleConnection conn = new OracleConnection(constring);
try
{
conn.Open();//打开指定的连接
OracleCommand com = conn.CreateCommand();
//写好想执行的Sql语句
com.CommandText =
"update fin_ipr_inmaininfo set name='wzd' where card_no='0000000002'";
com.ExecuteNonQuery();

}
catch
{
MessageBox.Show("erro");//如果发生异常,则提示出错
}
finally
{
conn.Close();//关闭打开的连接
}

#endregion
}
}
}

❹ java怎么连接数据库配置文件

你是说properties文件吗?

//读取配置文件DbUtil.properties,这里的DbUtil是此文件里的一个类,就是当前类
p.load(DbUtil.class.getClassLoader().getResourceAsStream("DbUtil.properties"));

//获取配置文件中的相关参数值
driver=p.getProperty("mysqlDriver");
url=p.getProperty("mysqlUrl");
user=p.getProperty("mysqlUser");
password=p.getProperty("mysqlPassword");

这里是DbUtil.properties文件里的内容:

##oracledatabase
oracleDriver=oracle.jdbc.driver.OracleDriver
oracleUrl=jdbc:oracle:thin:@localhost:1521:orcl
oracleUser=scott
oraclePassword=tiger

##mysqldatabase
mysqlDriver=com.mysql.jdbc.Driver
mysqlUrl=jdbc:mysql://localhost:3306/db_test
mysqlUser=root
mysqlPassword=root

❺ mysql的数据连接池怎么配置文件

mysql的数据连接池怎么配置文件
连接先建立一些连接,并且这些连接允许共享,因此这样就节省了每次连接的时间开销。Mysql数据库为例,连接池在Tomcat中的配置与使用。
1、创建数据库Student,表student
2、配置server.xml文件。Tomcat安装目录下conf中server.xml文件。
<GlobalNamingResources>
<Resource
name="jdbc/DBPool"
type="javax.sql.DataSource"
password=""
driverClassName="com.mysql.jdbc.Driver"
maxIdle="2"
maxWait="5000"
username="root"
url="jdbc:mysql://localhost:3306/student"
maxActive="3"
/>
</GlobalNamingResources>
name:指定连接池的名称
type:指定连接池的类,他负责连接池的事务处理
url:指定要连接的数据库
driverClassName:指定连接数据库使用的驱动程序
username:数据库用户名
password:数据库密码
maxWait:指定最大建立连接等待时间,如果超过此时间将接到异常
maxIdle:指定连接池中连接的最大空闲数
maxActive:指定连接池最大连接数
3、配置web.xml文件。
<web-app>
<resource-ref>
<description>mysql数据库连接池配置</description>
<res-ref-name>jdbc/DBPool</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
</web-app>
4、配置context.xml文件
与server.xml文件所在的位置相同。
<Context>
<ResourceLink
name="jdbc/DBPool"
type="javax.sql.DataSource"
global="jdbc/DBPool"
/>
</Context>
5、测试
DataSource pool = null;
Context env = null;
Connection conn = null;
Statement st = null;
ResultSet rs = null;
try{
env = (Context)new InitialContext().lookup("java:comp/env");
//检索指定的对象,返回此上下文的一个新实例
pool = (DataSource)env.lookup("jdbc/DBPool");
//获得数据库连接池
if(pool==null){out.printl("找不到指定的连接池!");}
con = pool.getConnection();
st = con.createStatement();
rs = st.executeQuery("select * from student");
}catch(Exception ex){out.printl(ne.toString());}

❻ 如何在配置文件里添加数据库链接

直接在spring的配置文件中applicationContext.xml文件中配置数据库连接也可以,但是有个问题,需要在url后带着使用编码集和指定编码集,出现了如下问题,&这个符号报错。

既然这样只能使用外部配置文件设置一些参数,在spring的配置文件applicationContext.xml中获取,然后配置连接数据库。

使用properties配置文件连接数据库,在src下新建jdbc.properties文件,按照自己的数据库名,用户名密码更改下面的配置。

在spring的配置文件applicatiContext.xml中加入(这里是引入配置文件),更改之前的数据库配置,名称和配置文件中的对应上即可。

❼ C#如何用配置文件连接数据库写好的配置文件放在哪里

你新建项目的时候,会有一个web.config的配置文件的
在里面的<connectionStrings</connectionStrings
<add一个数据库链接字符串就OK了,例如“<add
connectionString="Data
Source=.;Initial
Catalog=test;Integrated
Security=True;Connect
Timeout=30;"
name="DBHelplerDbConnection"/”
这个就是了,connectionString代表数据库链接字符串,name代表你想要引用的时候查找的名称。
完成以上的配置文件,就在你的DBhelper类里用ConfigurationManager进行连接
以下是我写的例子=
=。这是原创回答,如有错误,希望别见怪哈
string
strCon
=
ConfigurationManager.ConnectionStrings["这里是你刚才配置文件里连接的NAME"].ConnectionString;
就可以直接打开连接了,不知道对你有没有帮助·-·当学术交流吧

❽ 查询oracle数据库连接配置文件是否正确

摘要 Oracle客户端tnsnames.ora连接配置

热点内容
华为安卓如何更新鸿蒙 发布:2025-05-15 08:18:52 浏览:372
工商密码器是什么 发布:2025-05-15 08:18:50 浏览:750
c语言自考 发布:2025-05-15 07:52:42 浏览:501
压缩的玉 发布:2025-05-15 07:51:22 浏览:790
android的控件 发布:2025-05-15 07:50:36 浏览:553
南岗法院服务器ip地址 发布:2025-05-15 07:46:02 浏览:288
实况如何退出账号安卓 发布:2025-05-15 07:45:56 浏览:919
深入编译器 发布:2025-05-15 07:41:35 浏览:879
电信手机号服务密码怎么查 发布:2025-05-15 07:40:10 浏览:614
python全局变量文件 发布:2025-05-15 07:35:06 浏览:955