How does jsp and java connect to ibm DB2?

Source: Internet
Author: User
Tags ibm db2

The following articles mainly describe the correct operation steps for connecting jsp and java to ibm DB2. We all know that after the DB2 database is installed, you can copy the installation directory of the DB2 database, which is generally in C: \ Program Files \ IBM \ SQLLIB \ java‑based db2java.zip to the website lib, with the extension changed to jar.

Connection test:

 
 
  1. Class.forName("COM.ibm.DB2.jdbc.app.DB2Driver").newInstance();  
  2. //DriverManager.registerDriver (new COM.ibm.DB2.jdbc.app.DB2Driver());  

You do not need to use the previous line. You can use this line.

 
 
  1. String url = "jdbc: DB2: Database ";
  2. Connection con = DriverManager. getConnection (url, "user", "password ");
  3. Statement stmt = con. createStatement ();
  4. ResultSet rs = stmt.exe cuteQuery ("select * from ADMINISTRATOR. T2 order by id desc fetch first 10 rows only ");
  5. While (rs. next ())
  6. {
  7. Out. print (rs. getString (1) + "," + rs. getString (2) + "<br> ");
  8. }
  9. String cc = "insert into administrator. T2 (TITLE) values ('China ')";
  10. Stmt.exe cuteUpdate (cc );

In jcc mode, copy DB2jcc. jar to the lib directory of the website.

 
 
  1. <%
  2. Try
  3. {
  4. String url = "jdbc: DB2: // loaclhost: 50000/Database ";
  5. Class. forName ("com. ibm. DB2.jcc. DB2Driver"). newInstance ();
  6. Connection con = DriverManager. getConnection (url, "user", "password ");
  7. Statement stmt = con. createStatement ();
  8. ResultSet rs = stmt.exe cuteQuery ("select * from ADMINISTRATOR. T2 order by id desc fetch first 10 rows only ");
  9. While (rs. next ())
  10. {
  11. Out. print (rs. getString (1) + "," + rs. getString (2) + "<br> ");
  12. }
  13. String cc = "insert into administrator. T2 (TITLE) values ('China ')";
  14. Stmt.exe cuteUpdate (cc );
  15. }
  16. Catch (Exception Err)
  17. {
  18. Out. print (Err. toString ());
  19. }
  20. %>

The above content is an introduction to connecting jsp and java to ibm DB2. 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.