java连接池使用方法二

本文介绍了Java连接SQL Server和Sybase数据库的方法。通过Class.forName加载驱动,使用DriverManager.getConnection建立连接,并给出了URL格式及所需属性,如user和password。指出该方法适用于这两种数据库,其他数据库需查看对应文档。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

使用方法:
  连接sqlserver:
  Class.forName("net.sourceforge.jtds.jdbc.Driver").newInstance();
   String url ="jdbc:jtds:sqlserver://localhost:1433/check";//check是数据库名
   cnn = DriverManager.getConnection(url, user, password);

它的帮助 是这样写的:
driver:net.sourceforge.jtds.jdbc.Driver
url:
The URL format for jTDS is:
    jdbc:jtds:<server_type>://<server>[:<port>][/<database>][;<property>=<value>[;...]]
where <server_type> is one of either 'sqlserver' or 'sybase' (their meaning is quite obvious), <port> is the port the database server is listening to (default is 1433 for SQL Server and 7100 for Sybase) and <database> is the database name -- JDBC term: catalog -- (if not specified, the user's default database is used). The set of properties supported by jTDS is:

user (required)
User name to use for login. When using getConnection(String url, String user, String password) it's not required to set this property as it is passed as parameter, but you will have to set it when using getConnection(String url, Properties info) or TdsDataSource.
password (required)
Password to use for login. When using getConnection(String url, String user, String password) it's not required to set this property as it is passed as parameter, but you will have to set it when using getConnection(String url, Properties info) or TdsDataSource.
这是用于sybase或者sqlserver的,其它数据库你还要看它的文档

-------------------------------------------------------------------------------------
文章地址:http://community.youkuaiyun.com/Expert/topic/3589/3589555.xml?temp=.952572

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值