aspose file tools*
The moose likes JDBC and the fly likes JDBC connection for DB2 database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "JDBC connection for DB2 database" Watch "JDBC connection for DB2 database" New topic
Author

JDBC connection for DB2 database

Bitan Biswas
Greenhorn

Joined: Aug 05, 2011
Posts: 12
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<html>
<head>
<title>test3</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta name="GENERATOR" content="Rational Software Architect">
</head>
<body>
<%
try{
Class.forName("com.ibm.db2.jcc.DB2Driver");
}
catch(Exception e){
out.println(e);
}
%>
</body>
</html>



I added "db2jcc_license_cu.jar" and "db2jcc.jar" in project library but it still throwing java.lang.ClassNotFoundException: com.ibm.db2.jcc.DB2Driver
What should be the problem here?
Bitan Biswas
Greenhorn

Joined: Aug 05, 2011
Posts: 12
furthermore i create a java file in the same project folder. I complied and run successfully. I'm totally confused.. please help me.
the code for java file is


import java.sql.*;
public class db2conn {

public static void main(String[] args) {
try{
Class.forName("com.ibm.db2.jcc.DB2Driver");
Connection c = DriverManager.getConnection("jdbc:db2:OCM","","");
System.out.println("Connected "+c);
Statement s = c.createStatement();
System.out.println(s);
ResultSet rs = s.executeQuery("select * from PACK1.TEST1");
System.out.println(rs);
while(rs.next()){
System.out.println(rs.getString(1));
System.out.println(rs.getString(2));
System.out.println(rs.getString(3));
System.out.println(rs.getString(4));
}
}
catch(Exception e){
System.out.println(e);
}

}
}
Wendy Gibbons
Bartender

Joined: Oct 21, 2008
Posts: 1106

well, as you should in no way be putting SQL inside your jsp page, take that as a win. Write yourself a servlet and waste no more energy
Bitan Biswas
Greenhorn

Joined: Aug 05, 2011
Posts: 12
but i need dynamic page. i have to establish jdbc in jsp pages.
Wendy Gibbons
Bartender

Joined: Oct 21, 2008
Posts: 1106

a page can be completely dynamic using ajax and servlets.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18125
    
    8

Bitan Biswas wrote:but i need dynamic page. i have to establish jdbc in jsp pages.


No, you don't. You do your JDBC work in a servlet and then forward to a JSP to generate the HTML.
Wendy Gibbons
Bartender

Joined: Oct 21, 2008
Posts: 1106

from the jsp FAQ
http://www.coderanch.com/how-to/java/JspOrServlets
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JDBC connection for DB2 database
 
Similar Threads
jsp:include tag not processed in Tomcat 4.0.4 and Apache2 combination
window.Print() not working.
IllegalStateException: Cannot forward. Response already committed.
problem inserting data into MS Access
Content-type question