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

Why this code is not working in Command line

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 365
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes, your correct, i did't add classes12.zip in my system classpath.
Thanks alot
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic