• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Why this code is not running from 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
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.
Thanks
 
Ranch Hand
Posts: 1258
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You will need to include the oracle driver in your classpath when you execute your application. You can consult the documentation on how to do this. Also, you will want to double-check the package name to ensure that it is correct. (From your statement that it works in WSAD, it sounds like it's not a problem, but in case).
 
Ranch Hand
Posts: 227
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
include classes12.zip or classes11.zip (depending on the oracle version) in your classpath.
 
reply
    Bookmark Topic Watch Topic
  • New Topic