• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

JDBC connection for DB2 database

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
a page can be completely dynamic using ajax and servlets.
 
Sheriff
Posts: 26783
82
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
from the jsp FAQ
https://coderanch.com/how-to/java/JspOrServlets
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic