File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
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
 
jQuery in Action, 2nd edition
 
subject: Why this code is not working in Command line