• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Database connection within JSP

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi.
I tried oracle database connection within JSP but got class not found exception. I put the oracle jdbc driver "classes111.zip" in the WEB-INF/lib, still got the same error. My codes as following, thanks in advance for any help/ideas.
<%@ page import="java.sql.*" %>
<%@ page import="db.cashTypeBean" %>
<jsp:useBean id="cashType" class="db.cashTypeBean">
<%
Connection connection = null;
Statement statement = null;
ResultSet results = null;
try{
System.out.println("before loading driver...");
Class.forName("oracle.jdbc.driver.OracleDriver");
System.out.println("complete loading driver...");
String url = "jdbc racle:thin@hercules.fmd.cargill.com:1521:test";
String s = "IDV";
String query = "SELECT * FROM RDC.CSH_TYPS WHERE CSH_TYP_CD=" +s;
connection = DriverManager.getConnection(url, "dev_rdc", "dev_rdc");
statement = connection.createStatement();
results = statement.executeQuery(query);
if (results.next()){
cType.setCode(results.getString("CSH_TYP_CD"));
cType.setName(results.getString("LKUP_NM"));
}
connection.close();
}
catch (ClassNotFoundException e){
System.out.println("Fail to load database driver!");
}
finally{
try{ if(connection!=null) connection.close();}
catch (SQLException e) {}
}
%>
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check ur classpath...it seems that ur application is not getting the required classes.
 
hong zhang
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Triveni,
Thank you for your quick response. I'm using tomcat 4.0 beta 5. I updated classpath in the startup bat file, and the oracle driver loaded.
In connection statement, I got an error:
javax.servlet.ServletException:Sub Protocol must be specific in connection URL.
Don't know what it look for. Any advice? Thank you in advance!
Hong

Originally posted by triveni sangam:
Check ur classpath...it seems that ur application is not getting the required classes.


 
hong zhang
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I missed a ":" in specifying the database connection.
Thanks for your help, Triveni.
Hong
 
What is that? Is that a mongol hoarde? Can we fend them off with this tiny ad?
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic