aspose file tools*
The moose likes JDBC and the fly likes Why this code is not running from command line??? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Why this code is not running from command line???" Watch "Why this code is not running from command line???" New topic
Author

Why this code is not running from command line???

Swapna Agarwal
Ranch Hand

Joined: Jan 30, 2004
Posts: 37
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
Nathaniel Stoddard
Ranch Hand

Joined: May 29, 2003
Posts: 1258
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).


Nathaniel Stodard<br />SCJP, SCJD, SCWCD, SCBCD, SCDJWS, ICAD, ICSD, ICED
Dana Hanna
Ranch Hand

Joined: Feb 28, 2003
Posts: 227
include classes12.zip or classes11.zip (depending on the oracle version) in your classpath.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why this code is not running from command line???