Examples of connecting to the DB2 database java

Source: Internet
Author: User

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;

 
 
  1. import java.sql.CallableStatement;  
  2. import java.sql.Connection;  
  3. import java.sql.Driver;  
  4. import java.sql.DriverManager;  
  5. import java.sql.ResultSet;  
  6. import java.sql.SQLException;  
  7. import java.sql.Statement;  
  8. import java.util.Properties;  
  9. Description:  
  10. Copyright: (c) 2005  
  11. @author   
  12. @version 1.0  
  13. @since 2005-11-1  
  14. Version History: Date By Relative Bug Description  
  15. public class TestUDB  
  16. {  
  17. public static void main(String args[])  
  18. {  
  19. try  
  20. {  
  21. Class.forName(”com.ibm.DB2.jcc.DB2Driver”).newInstance();  
  22. String url = “jdbc:DB2://192.1.16.64:60004/testdb”;  
  23. String userid = “DB2test5″;  
  24. String password = “password”;  
  25. Connection conn = DriverManager.getConnection(url, userid, password);  
  26. Statement stmt = conn.createStatement();  
  27. ResultSet rs = stmt.executeQuery(”SELECT * FROM tbCode”);  
  28. if (rs == null)  
  29. {  
  30. System.out.print(”No resultset!”);  
  31. }  
  32. else  
  33. {  
  34. while (rs.next())  
  35. {  
  36. System.out.println(rs.getString(1));  
  37. }  
  38. System.out.println(”Output over!”);  
  39. }  
  40. stmt.close();  
  41. conn.close();  
  42. }  
  43. catch (SQLException ex)  
  44. {  
  45. ex.printStackTrace();  
  46. }  
  47. catch (java.lang.Exception ex)  
  48. {  
  49. ex.printStackTrace();  
  50. }  
  51. }  
  52. }  

The above content is an introduction to the java examples for connecting to the DB2 database. I hope you will have some gains.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.