• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why this code is not working in Command line

 
Swapna Agarwal
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 365
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Swapna Agarwal
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes, your correct, i did't add classes12.zip in my system classpath.
Thanks alot
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic