This week's book giveaway is in the Java in General forum.
We're giving away four copies of Event Streams in Action and have Alexander Dean & Valentin Crettaz on-line!
See this thread for details.
Win a copy of Event Streams in Action this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

JDBC connection for DB2 database

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<!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
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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);
}

}
}
 
Bartender
Posts: 1111
Eclipse IDE Oracle VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
but i need dynamic page. i have to establish jdbc in jsp pages.
 
Wendy L Gibbons
Bartender
Posts: 1111
Eclipse IDE Oracle VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
a page can be completely dynamic using ajax and servlets.
 
Sheriff
Posts: 24594
55
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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 L Gibbons
Bartender
Posts: 1111
Eclipse IDE Oracle VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
from the jsp FAQ
http://www.coderanch.com/how-to/java/JspOrServlets
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!