Posted By:
Sanjay_Singh
Posted On:
Thursday, November 28, 2002 12:00 AM
I have coded a Base Class for connecting to the Oracle database. The code is below.At runtime it gives the errorException in thread "main" java.lang.NoSuchMethod Error. mport java.sql.*; import java.io.*; import oracle.jdbc.driver.*; import java.math.*; public abstract class ConnectionBean implements Serializable { //private String myDriver = "oracle.jdbc.driver.OracleDriver"; private String myUrl = "jdbc:oracle:thin:@127.0.0.1:1521:SANJAY"; private String passWord = "tiger"; private String userName = "scott"; protected Connection myConn = null; public ConnectionBean (){
More>>
I have coded a Base Class for connecting to the Oracle database. The code is below.At runtime it gives the errorException in thread "main" java.lang.NoSuchMethod Error.
mport java.sql.*;
import java.io.*;
import oracle.jdbc.driver.*;
import java.math.*;
public abstract class ConnectionBean implements Serializable {
//private String myDriver = "oracle.jdbc.driver.OracleDriver";
private String myUrl = "jdbc:oracle:thin:@127.0.0.1:1521:SANJAY";
private String passWord = "tiger";
private String userName = "scott";
protected Connection myConn = null;
public ConnectionBean (){
}
public void makeConnection ( ) {
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
//DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
}
catch(Exception e){
System.out.println("Exception while loading driver" + e.getMessage());
}
System.out.println("Loaded Driver Successfully");
try{
myConn = DriverManager.getConnection(myUrl,userName,passWord);
}
catch(Exception e){
System.out.println("Exception while Connecting: " + e.getMessage());
e.printStackTrace();
}
System.out.println(" Established The Connection");
}
public abstract void cleanUp () throws Exception;
public void closeConnection () {
try{
myConn.close();
cleanUp();
}
catch(Exception e){
System.out.println("Exception while closing Connecting: " + e.getMessage());
e.printStackTrace();
}
System.out.println( "Connection is closed");
}
}
In the same directory I have a java class which is executing well.Following is the code.
import java.sql.*;
import java.math.*;
import oracle.jdbc.driver.*;
import java.io.*;
class TestConnection{
public static void main (String args[]){
Connection conn = null;
Statement stmt;
ResultSet rst;
String url = "jdbc:oracle:thin:@127.0.0.1:1521:SANJAY";
String userName = "scott";
String passWord = "tiger";
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
//DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
}
catch(Exception e){
System.out.println("Exception while loading driver" + e.getMessage());
}
System.out.println("Loaded Driver Successfully");
try{
conn = DriverManager.getConnection(url,userName,passWord);
}
catch(Exception e){
System.out.println("Exception while Connecting: " + e.getMessage());
e.printStackTrace();
}
System.out.println(" Established The Connection");
try {
stmt = conn.createStatement();
rst = stmt.executeQuery("SELECT EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO FROM Emp");
System.out.println("Query executd");
while(rst.next()) {
String empNumber = rst.getString("EMPNO");
String empName = rst.getString("ENAME");
String job = rst.getString("JOB");
String mgr = rst.getString("MGR");
String hireDate = rst.getString("HIREDATE");
String salary = rst.getString("SAL");
String comm = rst.getString("COMM");
String deptNo = rst.getString("DEPTNO");
System.out.print("Employee Name" + empName);
System.out.print("Employee's Job" + job);
System.out.print("Mgr" + mgr);
System.out.print("Hire Date" + hireDate);
System.out.print("COMM" + comm);
System.out.print("DeptNo" + deptNo);
}
}
catch(Exception e){
System.out.println("Exception after Statement and after while" + e.getMessage());
}
try{
conn.close();
}
catch(Exception e){
System.out.println("Exception while closing Connecting: " + e.getMessage());
e.printStackTrace();
}
System.out.println( "Connection is closed");
}
}
Please tell me what is wrong with the previous code.
Thanks
Sanjay
<<Less