How to use JSP to connect to a DB2 database

Source: Internet
Author: User
Tags microsoft frontpage

<% @ Page import = "Java. SQL .*"
Import = "Java. util .*"
Import = "Java. Io .*"
Contenttype = "text/html; charset = gb2312"
%>
<HTML>
<Head>
<Title> use a DB2 database </title>
<Meta name = "generator" content = "Microsoft FrontPage 4.0">
<Meta name = "progid" content = "FrontPage. Editor. Document">
</Head>
<Body>
<P align = "center"> <u> <font size = "5" face = "文 "> use JSP to connect to the DB2 database </font> </u> </P>
<%!
String host = "192.1.1.127"; // Database Host
String database = "myweb"; // Database Name
String user = "db2admin"; // User Name
String pass = "db2admin"; // Password
%> <% Java. SQL. Connection sqlconn; // database connection object
Java. SQL. Statement sqlstmt; // statement object
Java. SQL. resultset sqlrst; // result set object
Try {

try {
// register the JDBC driver object
// The following two methods can all be used
// drivermanager. registerdriver (New com.ibm.db2.jdbc.net. db2driver (); // DB2
class. forname ("com.ibm.db2.jdbc.net. db2driver "). newinstance (); // DB2
}< br> catch (classnotfoundexception e)
{out. print (E);
}< br> // connect to the database
sqlconn = Java. SQL. drivermanager. getconnection ("JDBC: DB2: //" + host + "/" + database, user, pass); // create a statement object
out. P RINT ("connected to the database! ");
%>

<%
// close the result set object
// sqlrst. close ();
// close the statement object
// sqlstmt. close ();
// close the database connection
sqlconn. close ();
}catch (sqlexception e)
{out. print ("failed to connect to the database! ");
out. Print (E);
}< BR >%>

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.