How to use JSP to connect DB2 database _jsp programming

Source: Internet
Author: User
Tags db2 microsoft frontpage
<% @page import= "java.sql.*"
import = "Java.util.*"
import = "Java.io.*"
Contenttype= "text/html; charset=gb2312 "
%>
<title> using DB2 database </title>
<meta name= "generator" content= "Microsoft FrontPage 4.0" >
<meta name= "ProgId" content= "FrontPage.Editor.Document" >
<body>
<p align= "center" ><u><font size= "5" face= "XXFarEastFont-Arial" > Use JSP to connect to 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 objects
Java.sql.Statement sqlstmt; Statement Object
Java.sql.ResultSet Sqlrst; Result set Object
try{

try{
Registering JDBC Driver objects
The following two methods are available
Drivermanager.registerdriver (New COM.ibm.db2.jdbc.net.DB2Driver ()); Db2
Class.forName ("COM.ibm.db2.jdbc.net.DB2Driver"). newinstance (); Db2
}
catch (ClassNotFoundException e)
{Out.print (e);
}
Connecting to a database
sqlconn= java.sql.DriverManager.getConnection ("jdbc:db2://" +host+ "/" +database,user,pass);//Create Statement Object
Out.print ("Connect the database successfully!") ");
%>
</body>
<%
Close result Set Object
Sqlrst.close ();
Close Statement Object
Sqlstmt.close ();
To close a database connection
Sqlconn.close ();
}catch (SQLException e)
{out.print ("Connection database failed!");
Out.print (e);
}
%>
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.