以下的文章主要是介紹正確連接DB2數據庫java例子的列舉,以下就是文章的連接DB2數據庫java例子的列舉對主要內容的詳細描述,望大家在浏覽之後會對連接DB2數據庫java例子的列舉有更深的了解。
package com.dd.test;
- import java.sql.CallableStatement;
- import java.sql.Connection;
- import java.sql.Driver;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- import java.util.Properties;
- Description:
- Copyright: (c) 2005
- @author
- @version 1.0
- @since 2005-11-1
- Version History: Date By Relative Bug Description
- public class TestUDB
- {
- public static void main(String args[])
- {
- try
- {
- Class.forName(”com.ibm.DB2.jcc.DB2Driver”).newInstance();
- String url = “jdbc:DB2://192.1.16.64:60004/testdb”;
- String userid = “DB2test5″;
- String password = “password”;
- Connection conn = DriverManager.getConnection(url, userid, password);
- Statement stmt = conn.createStatement();
- ResultSet rs = stmt.executeQuery(”SELECT * FROM tbCode”);
- if (rs == null)
- {
- System.out.print(”No resultset!”);
- }
- else
- {
- while (rs.next())
- {
- System.out.println(rs.getString(1));
- }
- System.out.println(”Output over!”);
- }
- stmt.close();
- conn.close();
- }
- catch (SQLException ex)
- {
- ex.printStackTrace();
- }
- catch (java.lang.Exception ex)
- {
- ex.printStackTrace();
- }
- }
- }
以上的相關內容就是對連接DB2數據庫的java例的介紹,望你能有所收獲。