The following articles mainly introduce examples of correctly connecting to the DB2 database java. The following is a detailed description of the main contents of the article's examples of connecting to the DB2 database java, I hope you will have a better understanding of the examples of connecting to the DB2 database 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();
- }
- }
- }
The above content is an introduction to the java examples for connecting to the DB2 database. I hope you will have some gains.