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

Oracle 9i thru WSAD5.0 Problem!!!!!

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI,
I am trying ti retrive data from oracle9i thro WSAD,the statement"import oracle.jdbc.driver.*;" is not working in WSAD.But same code when i save it in a notepad and running on comand line its working fine and getting the result,could any one help me?
import java.sql.*;
import oracle.jdbc.driver.*;
class JDBCVersion
{
public static void main (String args[])
throws SQLException
{
// Load the Oracle JDBC driver
DriverManager.registerDriver
(new oracle.jdbc.driver.OracleDriver());
Connection conn = DriverManager.getConnection
("jdbc racle:thin:@localhost:1521:myDB","scott","tiger");
// Create Oracle DatabaseMetaData object
DatabaseMetaData meta = conn.getMetaData();
// gets driver info:
System.out.println("JDBC driver version is " + meta.getDriverVersion());
Statement smt=conn.createStatement();
ResultSet r = smt.executeQuery("SELECT * FROM emp");
while(r.next())
{
int j=r.getInt("empno");
String s = r.getString("ename");
System.out.println("Employee Details = " + " " +s+ " " + j);
}
}
}
 
author & internet detective
Posts: 42056
926
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is the jar/zip containing oracle.jdbc.driver.* in the classpath for WSAD? It should be in the server's classpath and the project's classpath.
 
srinivasa reddy
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have added the Jar file in WSAD in the following locations.
1)Window-->Preferences-->Classpath Variables-->CLASSPATH=C:/oracle/ora9i/jdbc/lib/classes12.zip
2)pROJECT-->pROPERTIES-->Java Build Path-->Libraries-->addJars
Is that ok?
After that i have created a class and a servlet,the code is running fine in class but in servlet its giving an exception.Here is the class file code and result
import java.sql.*;
import oracle.jdbc.driver.*;
class JDBCVersion
{
public static void main (String args[])
throws SQLException
{
// Load the Oracle JDBC driver
DriverManager.registerDriver
(new oracle.jdbc.driver.OracleDriver());
Connection conn = DriverManager.getConnection
("jdbc racle:thin:@localhost:1521:esr","scott","tiger");
// Create Oracle DatabaseMetaData object
DatabaseMetaData meta = conn.getMetaData();
// gets driver info:
System.out.println("JDBC driver version is " + meta.getDriverVersion());
Statement smt=conn.createStatement();
ResultSet r = smt.executeQuery("SELECT * FROM emp");
while(r.next())
{
int j=r.getInt("empno");
String s = r.getString("ename");
String d = r.getString("job");
System.out.println("Employee Details = " + " " +s+ " " + j+ " " +d);
}
}
}
RESULT:
JDBC driver version is 9.2.0.1.0
Employee Details = SMITH 7369 CLERK
Employee Details = ALLEN 7499 SALESMAN
Employee Details = WARD 7521 SALESMAN
Employee Details = JONES 7566 MANAGER
Here is Servlet Code and result:
import java.util.*;
import javax.servlet.*;
import java.sql.*;
import javax.servlet.http.*;
import oracle.jdbc.driver.*;
//import oracle.jdbc.driver.*;
class MyConnection extends HttpServlet{
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
try{
DriverManager.registerDriver
(new oracle.jdbc.driver.OracleDriver());
Connection conn = DriverManager.getConnection
("jdbc racle:thin:@localhost:1521:esr","scott","tiger");

DatabaseMetaData meta = conn.getMetaData();
System.out.println("JDBC driver version is " + meta.getDriverVersion());
Statement smt=conn.createStatement();
ResultSet r = smt.executeQuery("SELECT * FROM emp");
while(r.next())
{
int j=r.getInt("empno");
String s = r.getString("ename");
System.out.println("Employee Details = " + " " +s+ " " + j);
}

}
catch(Exception e){
System.out.println("exception");
}
}

}
rESULT:THE PAGE CANNOT BE FOUND
My doubt is why the same code is working fine in Java class but not in the servlet?
Thanks.
 
Jeanne Boyarsky
author & internet detective
Posts: 42056
926
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This question appears to be getting more traffic in the servlet forum. (although it's really a WSAD question)
See my post in servlets:
https://coderanch.com/t/357013/Servlets/java/Oracle-Connectivity-thru-wsad
 
Tomorrow is the first day of the new metric calendar. Comfort me tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic