Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JSP not connecting to DB2

Status
Not open for further replies.

vikind

MIS
Dec 11, 2003
58
US
hi kanifar,

thanks for ur help!!

i tried to use the following JSP to connect to a DB2 database..but it gives me an error

"Class loading error".. i know the problem is with class not found but how can i handle this

error also i am using Websphere 5.1 application developer to create this JSP file..

any place where i am missing anything w.r.t path ..thanks

JSP FILE:
------------

<html>
<head>
<%@ page
import = &quot;java.io.*&quot;
import = &quot;java.lang.*&quot;
import = &quot;java.sql.*&quot;
%>
<title>
JSP Example 2
</title>
</head>
<body>
<h1>JSP Example 3</h1>
<%
String place;
Connection dbconn;
ResultSet results;
PreparedStatement sql;
try
{
Class.forName(&quot;COM.ibm.db2.jdbc.app.DB2Driver&quot;);
try
{
String code,desc;
boolean doneheading = false;
dbconn = DriverManager.getConnection(&quot;jdbc:db2:SABITDAT&quot;,&quot;sbdev&quot;,&quot;sbtdev&quot;);
sql = dbconn.prepareStatement(&quot;SELECT * FROM SBDATA.EM_STATE&quot;);
results = sql.executeQuery();
while(results.next())
{
if(! doneheading)
{
out.println(&quot;<table border=2>&quot;);
doneheading = true;
}
code = results.getString(1);
desc = results.getString(2);
out.println(&quot;<tr><td>&quot; + code);
out.println(&quot;<td>&quot; + desc);

}
if(doneheading)
{
out.println(&quot;</table>&quot;);
}
else
{
out.println(&quot;No matches for &quot;);
}
}
catch (SQLException s)
{
out.println(&quot;SQL Error<br>&quot;);
}
}
catch (ClassNotFoundException err)
{
out.println(&quot;Class loading error&quot;);
}
%>
</body>
</html>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top