% @ Pageimportjava. SQL. * importjava. util. * importjava. io. * contentTypetexthtml; charsetgb2312 % htmlheadtitle use the Db2 database metadata. Editor. enentheadbo DB2
<% @ Page import = "java. SQL .*" Import = "java. util .*" Import = "java. io .*" ContentType = "text/html; charset = gb2312" %> Use a Db2 database
Use JSP to connect to the Db2 database <%! 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 { Out. print ("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 ); } %>
|