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

1529

被折叠的 条评论
为什么被折叠?



