This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Websphere and the fly likes Why this code is not working in Command line Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Products » Websphere
Bookmark "Why this code is not working in Command line" Watch "Why this code is not working in Command line" New topic
Author

Why this code is not working in Command line

Swapna Agarwal
Ranch Hand

Joined: Jan 30, 2004
Posts: 37
The following code is working fine in WSAD5, but not from command line, may i know the reason
import java.io.*;
import java.sql.*;
import oracle.jdbc.driver.*;
public class DBServlet{
public static void main(String args[]){
try
{

Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn = DriverManager.getConnection("jdbc racle:thin:@localhost:1521:myDB","hr", "hr");
Statement smt = conn.createStatement();
ResultSet r = smt.executeQuery("Select * from employees");
while(r.next())
{
int j=r.getInt("EMPLOYEE_ID");
String s = r.getString("EMPLOYEE_ID");
String s2 = r.getString("LAST_NAME");
System.out.println("ID = " +j +"Name = " + " " +s +"LastName =" +s2);
}
smt.close();
conn.close();
}
catch(Exception e)
{
System.out.println("<<>>>>>"+e);
}
}
}

Its giving an error.
import oracle.jdbc.driver.*; Cannot identified.
This code is working fine in WSAD but not from Command line
Scott Duncan
Ranch Hand

Joined: Nov 01, 2002
Posts: 363
That is because the oracle driver is not in the machines classpath where I think you'll find that WSAD has included this in it's build path. When running from the command line you'll have to make sure the classpath is set appropriately. In other words the classes12.zip file (I think, I havn't worked with oracle in a long time) needs to be included in the system's classpath.


No more rhymes! I mean it!<br /> <br />Does anybody want a peanut?
Swapna Agarwal
Ranch Hand

Joined: Jan 30, 2004
Posts: 37
yes, your correct, i did't add classes12.zip in my system classpath.
Thanks alot
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why this code is not working in Command line
 
Similar Threads
Oracle9i Connectivity thru wsad5.o
Why this code is not running from command line???
testing
Oracle 9i thru WSAD5.0 Problem!!!!!
Servlet and Java class