Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
srinivasa reddy
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • 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);
}
}
}
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35279
384
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • 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
  • 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
Marshal
Posts: 35279
384
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • 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:
http://www.coderanch.com/t/357013/Servlets/java/Oracle-Connectivity-thru-wsad
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic