jdbc连接db2

public static void main(String[] args) {
  Connection conn = null;
  PreparedStatement ps = null;
  ResultSet rs = null;
  String url = "jdbc:db2://192.168.3.23:50000/dbname",
      username = "username",
      password = "password";

  try {
   Class.forName("com.ibm.db2.jcc.DB2Driver");
   conn = DriverManager.getConnection(url, username, password);
   ps = conn.prepareStatement("select colname from tablename");
   rs = ps.executeQuery();
   while (rs.next()) {
    System.out.println(rs.getString(1));
   }
  } catch (Exception e) {
   e.printStackTrace();
  } finally {
   try {
    if (rs != null) rs.close();
    if (ps != null) ps.close();
    if (conn != null) conn.close();
   } catch (SQLException e) {
    e.printStackTrace();
   }
  }
 }

posted on 2007-07-19 17:46 心砚 阅读(379) 评论(0)  编辑  收藏 所属分类: DB


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


网站导航:
 
<2024年4月>
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011

导航

统计

常用链接

留言簿(2)

随笔分类

文章分类

文章档案

Forum

搜索

最新评论

阅读排行榜

评论排行榜