shilpi84
asked on
java program cannot retrieve records from oracle DB
i made this prg. in java .
it inserts records into the databse but doesnt retrieve them...
i checked using SQL-PLUS
the records were created ...
but the records don't get displayed
what could be wrong?
__________________________ __________ __________ _____
import java.sql.*;
class A1
{
public static void main(String args[])
{
try
{
Class.forName("sun.jdbc.od bc.JdbcOdb cDriver");
Connection c=DriverManager.getConnect ion("jdbc: odbc:pranj al","scott ","tiger") ;
System.out.println("got connection");
Statement stmt=c.createStatement();
String sq="insert into empl values('d2','73141')";
stmt.executeUpdate(sq);
sq="select fname,ssn from employee";
ResultSet rs=stmt.executeQuery(sq);
System.out.println("test2" );
while(rs.next())
{
System.out.println("hi");
System.out.println(rs.getS tring("fna me") +" " +rs.getString("ssn"));
}
rs.close();
stmt.close();
c.close();
}
catch(ClassNotFoundExcepti on e1)
{}
catch(SQLException e2)
{}
catch(Exception e3)
{}
}
}
__________________________ __________ __________ ______
it inserts records into the databse but doesnt retrieve them...
i checked using SQL-PLUS
the records were created ...
but the records don't get displayed
what could be wrong?
__________________________
import java.sql.*;
class A1
{
public static void main(String args[])
{
try
{
Class.forName("sun.jdbc.od
Connection c=DriverManager.getConnect
System.out.println("got connection");
Statement stmt=c.createStatement();
String sq="insert into empl values('d2','73141')";
stmt.executeUpdate(sq);
sq="select fname,ssn from employee";
ResultSet rs=stmt.executeQuery(sq);
System.out.println("test2"
while(rs.next())
{
System.out.println("hi");
System.out.println(rs.getS
}
rs.close();
stmt.close();
c.close();
}
catch(ClassNotFoundExcepti
{}
catch(SQLException e2)
{}
catch(Exception e3)
{}
}
}
__________________________
ASKER
ok... this is my latest code... and it works!
import java.sql.*;
class A1
{
public static void main(String args[])
{
try
{
Class.forName("sun.jdbc.od bc.JdbcOdb cDriver");
Connection c=DriverManager.getConnect ion("jdbc: odbc:shilp i","scott" ,"tiger");
System.out.println("got connection");
Statement stmt=c.createStatement();
String sq="select fname,ssn from empl";
//stmt.executeUpdate(sq);
ResultSet rs=stmt.executeQuery(sq);
System.out.println("hi");
while(rs.next())
{
System.out.println(rs.getS tring("fna me") +" " +rs.getString("ssn"));
}
rs.close();
stmt.close();
c.close();
}
catch(ClassNotFoundExcepti on e1)
{}
catch(SQLException e2)
{}
catch(Exception e3)
{}
}
}
import java.sql.*;
class A1
{
public static void main(String args[])
{
try
{
Class.forName("sun.jdbc.od
Connection c=DriverManager.getConnect
System.out.println("got connection");
Statement stmt=c.createStatement();
String sq="select fname,ssn from empl";
//stmt.executeUpdate(sq);
ResultSet rs=stmt.executeQuery(sq);
System.out.println("hi");
while(rs.next())
{
System.out.println(rs.getS
}
rs.close();
stmt.close();
c.close();
}
catch(ClassNotFoundExcepti
{}
catch(SQLException e2)
{}
catch(Exception e3)
{}
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
hoomanv it's working now...
but i have a similar problem in JSP ..
the same thing is not working in JSP
...
if you could please check it out.
here's the link:
https://www.experts-exchange.com/questions/22031824/JSP-program-not-retrieving-records-from-oracle.html
but i have a similar problem in JSP ..
the same thing is not working in JSP
...
if you could please check it out.
here's the link:
https://www.experts-exchange.com/questions/22031824/JSP-program-not-retrieving-records-from-oracle.html
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
ok ... i put e.printStackTrace() in every catch. this is what i got
__________________________ __________ __________ _______
C:\>javac A1.java
C:\>java A1
got connection
java.sql.SQLException: [Microsoft][ODBC driver for Oracle][Oracle]ORA-00942: tab
le or view does not exist
at sun.jdbc.odbc.JdbcOdbc.cre ateSQLExce ption(Unkn own Source)
at sun.jdbc.odbc.JdbcOdbc.sta ndardError (Unknown Source)
at sun.jdbc.odbc.JdbcOdbc.SQL ExecDirect (Unknown Source)
at sun.jdbc.odbc.JdbcOdbcStat ement.exec ute(Unknow n Source)
at sun.jdbc.odbc.JdbcOdbcStat ement.exec uteQuery(U nknown Source)
at A1.main(A1.java:21)
C:\>
__________________________
C:\>javac A1.java
C:\>java A1
got connection
java.sql.SQLException: [Microsoft][ODBC driver for Oracle][Oracle]ORA-00942: tab
le or view does not exist
at sun.jdbc.odbc.JdbcOdbc.cre
at sun.jdbc.odbc.JdbcOdbc.sta
at sun.jdbc.odbc.JdbcOdbc.SQL
at sun.jdbc.odbc.JdbcOdbcStat
at sun.jdbc.odbc.JdbcOdbcStat
at A1.main(A1.java:21)
C:\>
ASKER
please omit my last post
i'm reposting in stackTrace
i'm reposting in stackTrace
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
no hoomanv ... i by mistake input some chars right after the empl table name...
i made this mistake just this time...
String sq="insert into empl values('d2','73141')";
stmt.executeUpdate(sq);
sq="select fname,ssn from employee";
...
i was using different table names
i recompiled the original program and its now running
i made this mistake just this time...
String sq="insert into empl values('d2','73141')";
stmt.executeUpdate(sq);
sq="select fname,ssn from employee";
...
i was using different table names
i recompiled the original program and its now running
ASKER
yes i did all that and its working ... thanks ...all of you
ASKER
actually i'd ported programs from one PC to another.
ASKER
i still dont get ehy the same thing is not working in JSP:
similar JSP question:
https://www.experts-exchange.com/questions/22031824/JSP-program-not-retrieving-records-from-oracle.html
similar JSP question:
https://www.experts-exchange.com/questions/22031824/JSP-program-not-retrieving-records-from-oracle.html
ASKER
i'm closing this question now.
change this line: ResultSet rs=stmt.executeQuery( sq );
to:
stmt = c.prepareStatement(sq);
ResultSet rs = stmt.executeQuery();