ivaneeo's blog

自由的力量,自由的生活。

  BlogJava :: 首页 :: 联系 :: 聚合  :: 管理
  669 Posts :: 0 Stories :: 64 Comments :: 0 Trackbacks
Class.forName(props.getProperty("driver"));
String url = props.getProperty("url");
Connection con = DriverManager.getConnection(url, props);
//        showWarnings(con.getWarnings());
initLanguage(con);
return con;

上面的Connection类的方法getWarnings检索调用这个Connection对象的第一个警告.如果有多个可以用getNextWarning方法得到.

public void showWarnings(SQLWarning w) {
  while (w != null) {
    System.out.println(w.getMessage());
    w = w.getNextWarning();
  }
}

private void initLanguage(Connection con) throws SQLException {
Statement stmt = con.createStatement();

stmt.executeUpdate("set LANGUAGE 'us_english'");
stmt.close();
}
上面函数显示了一个比较简单的调用语句的方法.

这里是使用的属性文件注册.属性文件如下:
--------------------------------------------------------------------
#属性文件connection.properties.tmpl
#
# The URL of the server to which you want to connect
#
driver=net.sourceforge.jtds.jdbc.Driver
url=jdbc:jtds:sqlserver://localhost/dbname
USER=XXXX
PASSWORD=YYYY
SERVERNAME=localhost
PORTNUMBER=1433
DATABASENAME=dbname
XAEMULATION=true

#
# TDS Version
#

#
# Use this for MS SQL Server 6.5+
#
#TDS=4.2

#
# Use this for Sybase 10+
#
#TDS=5.0

#
# Use this for MS SQL Server 7.0+
#
#TDS=7.0

#
# Use this for MS SQL Server 2000 (default)
#
TDS=8.0
--------------------------------------------------------------------

读入属性文件如下:
String CONNECTION_PROPERTIES = "conf/connection.properties";
File propFile = new File(fileName);
if (!propFile.exists()) {
  fail("Connection properties not found (" + propFile + ").");
}
try {
Properties props = new Properties();
props.load(new FileInputStream(propFile));
return props;
}
catch (IOException e) {
throw new RuntimeException(e.getMessage());
}
这里是fail函数是使用了junit的fail方法,表示测试失败.
posted on 2005-08-04 21:13 ivaneeo 阅读(614) 评论(0)  编辑  收藏 所属分类: java魔力

只有注册用户登录后才能发表评论。


网站导航: