gdlp2004
asked on
SQL Exception Error
Can anyone inform me what this error means.
unreported exception: java.sql.SQLException; must be caught or declared to be thrown
unreported exception: java.sql.SQLException; must be caught or declared to be thrown
ASKER
<%!
public String doSomthing() {
Connection conn2 = null;
try {
Class.forName("oracle.jdbc .driver.Or acleDriver ");
conn2 = DriverManager.getConnectio n(
"jdbc:oracle:thin:@divodb0 02:1521:sa lest01",
"public_gdlp",
"public");
}
catch(SQLException e) {
System.out.println("SQLExc eption: " + e.getMessage() + "<BR>");
while((e = e.getNextException()) != null)
System.out.println(e.getMe ssage() + "<BR>");
}
ResultSet r5;
String strMyString = "";
String udc = "Select udc FROM public_gdlp.udc where treeid = 2 and udcseq = 1";
Statement stmt2 = conn2.createStatement();
r5 = stmt2.executeQuery(udc);
while (r5.next()) {
strMyString = r5.getString("countless");
}
return strMyString;
}
%>
Here is the code that is giving me the error
public String doSomthing() {
Connection conn2 = null;
try {
Class.forName("oracle.jdbc
conn2 = DriverManager.getConnectio
"jdbc:oracle:thin:@divodb0
"public_gdlp",
"public");
}
catch(SQLException e) {
System.out.println("SQLExc
while((e = e.getNextException()) != null)
System.out.println(e.getMe
}
ResultSet r5;
String strMyString = "";
String udc = "Select udc FROM public_gdlp.udc where treeid = 2 and udcseq = 1";
Statement stmt2 = conn2.createStatement();
r5 = stmt2.executeQuery(udc);
while (r5.next()) {
strMyString = r5.getString("countless");
}
return strMyString;
}
%>
Here is the code that is giving me the error
stmt.executeQuery will also throw the exception...
chage the code to be..
<%!
public String doSomthing() {
Connection conn2 = null;
String strMyString = "";
try {
Class.forName("oracle.jdbc .driver.Or acleDriver ");
conn2 = DriverManager.getConnectio n(
"jdbc:oracle:thin:@divodb0 02:1521:sa lest01",
"public_gdlp",
"public");
ResultSet r5;
String udc = "Select udc FROM public_gdlp.udc where treeid = 2 and udcseq = 1";
Statement stmt2 = conn2.createStatement();
r5 = stmt2.executeQuery(udc);
while (r5.next()) {
strMyString = r5.getString("countless");
}
}
catch(SQLException e) {
System.out.println("SQLExc eption: " + e.getMessage() + "<BR>");
while((e = e.getNextException()) != null)
System.out.println(e.getMe ssage() + "<BR>");
}
return strMyString;
}
%>
chage the code to be..
<%!
public String doSomthing() {
Connection conn2 = null;
String strMyString = "";
try {
Class.forName("oracle.jdbc
conn2 = DriverManager.getConnectio
"jdbc:oracle:thin:@divodb0
"public_gdlp",
"public");
ResultSet r5;
String udc = "Select udc FROM public_gdlp.udc where treeid = 2 and udcseq = 1";
Statement stmt2 = conn2.createStatement();
r5 = stmt2.executeQuery(udc);
while (r5.next()) {
strMyString = r5.getString("countless");
}
}
catch(SQLException e) {
System.out.println("SQLExc
while((e = e.getNextException()) != null)
System.out.println(e.getMe
}
return strMyString;
}
%>
>> while (r5.next()) {
this could throw sql exception and you are not catching it.
try change
>>public String doSomthing() {
to
public String doSomthing() throws SQLException {
this could throw sql exception and you are not catching it.
try change
>>public String doSomthing() {
to
public String doSomthing() throws SQLException {
oops, Kuldeepchaturvedi also work!
:-) I figured that you were resorting to your old habit of reading the question and then start typing the suggestion/solution..
.......
.......
ASKER
Ok, well that fixed all but one of those errors. I am still getting one more pointing to the line starting class.forname....
actually, i'm a little slow. I opened the Q, type the half, then pick up a call or two. then finished the rest. :-)
>>>>Ok, well that fixed all but one of those errors. I am still getting one more pointing to the line starting class.forname....
whats the error?/
whats the error?/
ASKER
it's the same error i was getting before
unreported exception: java.sql.SQLException; must be caught or declared to be thrown
unreported exception: java.sql.SQLException; must be caught or declared to be thrown
use this:
public String doSomthing() throws java.sql.SQLException, ClassNotFoundException {
public String doSomthing() throws java.sql.SQLException, ClassNotFoundException {
what solution you adopted?? mine or kenneth's??
can you post your modified code..?? because now all you method is inside a try block so its not suppose to throw a SQLException any more..
can you post your modified code..?? because now all you method is inside a try block so its not suppose to throw a SQLException any more..
ASKER
<%!
public String doSomthing() {
Connection conn2 = null;
String strMyString = "";
try {
Class.forName("oracle.jdbc .driver.Or acleDriver ");
conn2 = DriverManager.getConnectio n(
"jdbc:oracle:thin:@divodb0 02:1521:sa lest01",
"public_gdlp",
"public");
ResultSet r5;
String udc = "Select udc FROM public_gdlp.udc where treeid = 2 and udcseq = 1";
Statement stmt2 = conn2.createStatement();
r5 = stmt2.executeQuery(udc);
while (r5.next()) {
strMyString = r5.getString("countless");
}
}
catch(SQLException e) {
System.out.println("SQLExc eption: " + e.getMessage() + "<BR>");
while((e = e.getNextException()) != null)
System.out.println(e.getMe ssage() + "<BR>");
}
return strMyString;
}
%>
here is the adjusted code
public String doSomthing() {
Connection conn2 = null;
String strMyString = "";
try {
Class.forName("oracle.jdbc
conn2 = DriverManager.getConnectio
"jdbc:oracle:thin:@divodb0
"public_gdlp",
"public");
ResultSet r5;
String udc = "Select udc FROM public_gdlp.udc where treeid = 2 and udcseq = 1";
Statement stmt2 = conn2.createStatement();
r5 = stmt2.executeQuery(udc);
while (r5.next()) {
strMyString = r5.getString("countless");
}
}
catch(SQLException e) {
System.out.println("SQLExc
while((e = e.getNextException()) != null)
System.out.println(e.getMe
}
return strMyString;
}
%>
here is the adjusted code
ASKER
I also used your code and not kenneths
Okay this is bound to work...
<%!
public String doSomthing() {
Connection conn2 = null;
String strMyString = "";
try {
Class.forName("oracle.jdbc .driver.Or acleDriver ");
conn2 = DriverManager.getConnectio n(
"jdbc:oracle:thin:@divodb0 02:1521:sa lest01",
"public_gdlp",
"public");
ResultSet r5;
String udc = "Select udc FROM public_gdlp.udc where treeid = 2 and udcseq = 1";
Statement stmt2 = conn2.createStatement();
r5 = stmt2.executeQuery(udc);
while (r5.next()) {
strMyString = r5.getString("countless");
}
}
catch(SQLException e) {
System.out.println("SQLExc eption: " + e.getMessage() + "<BR>");
while((e = e.getNextException()) != null)
System.out.println(e.getMe ssage() + "<BR>");
}
catch(ClassNotFoundExcepti on cnfe) {
System.out.println("ClassN otFoundExc eption: " + cnfe.getMessage() + "<BR>");
while((cnfe = cnfe.getNextException()) != null)
System.out.println(cnfe.ge tMessage() + "<BR>");
}
catch(Exception e1) { //this is the mother of all Exception..... nobody can bypass this one..:-)
System.out.println("Genera lException : " + e1.getMessage() + "<BR>");
while((e1 = e1.getNextException()) != null)
System.out.println(e1.getM essage() + "<BR>");
}
return strMyString;
}
%>
<%!
public String doSomthing() {
Connection conn2 = null;
String strMyString = "";
try {
Class.forName("oracle.jdbc
conn2 = DriverManager.getConnectio
"jdbc:oracle:thin:@divodb0
"public_gdlp",
"public");
ResultSet r5;
String udc = "Select udc FROM public_gdlp.udc where treeid = 2 and udcseq = 1";
Statement stmt2 = conn2.createStatement();
r5 = stmt2.executeQuery(udc);
while (r5.next()) {
strMyString = r5.getString("countless");
}
}
catch(SQLException e) {
System.out.println("SQLExc
while((e = e.getNextException()) != null)
System.out.println(e.getMe
}
catch(ClassNotFoundExcepti
System.out.println("ClassN
while((cnfe = cnfe.getNextException()) != null)
System.out.println(cnfe.ge
}
catch(Exception e1) { //this is the mother of all Exception..... nobody can bypass this one..:-)
System.out.println("Genera
while((e1 = e1.getNextException()) != null)
System.out.println(e1.getM
}
return strMyString;
}
%>
ASKER
this fixed the Sql exceptions, now I get an exception that says the method getNextException is not found in class java.lang.exception
catch(SQLException e) {
System.out.println("SQLExc eption: " + e.getMessage() + "<BR>");
while((e = e.getNextException()) != null)
System.out.println(e.getMe ssage() + "<BR>");
}
catch(ClassNotFoundExcepti on cnfe) {
System.out.println("ClassN otFoundExc eption: " + cnfe.getMessage() + "<BR>");
}
catch(Exception e1) { //this is the mother of all Exception..... nobody can bypass this one..:-)
System.out.println("Genera lException : " + e1.getMessage() + "<BR>");
}
System.out.println("SQLExc
while((e = e.getNextException()) != null)
System.out.println(e.getMe
}
catch(ClassNotFoundExcepti
System.out.println("ClassN
}
catch(Exception e1) { //this is the mother of all Exception..... nobody can bypass this one..:-)
System.out.println("Genera
}
dumb me!!!
shd have seen it...
there is no method in class Exception with name getNextException...!!
shd have seen it...
there is no method in class Exception with name getNextException...!!
btw, system.out.println will not put anything on your page so the "<BR>" is pointless.
for the simplist code, just throw it as I suggested, because you don't do anything meaningful in the catch block.
for the simplist code, just throw it as I suggested, because you don't do anything meaningful in the catch block.
sorry, should read as
... because you are not doing anything ...
... because you are not doing anything ...
this should work, (you don't need public):
<%!
private String doSomthing() throws java.sql.SQLException, ClassNotFoundException {
Connection conn2 = null;
String strMyString = "";
Class.forName("oracle.jdbc .driver.Or acleDriver ");
conn2 = DriverManager.getConnectio n(
"jdbc:oracle:thin:@divodb0 02:1521:sa lest01",
"public_gdlp",
"public");
ResultSet r5;
String udc = "Select udc FROM public_gdlp.udc where treeid = 2 and udcseq = 1";
Statement stmt2 = conn2.createStatement();
r5 = stmt2.executeQuery(udc);
while (r5.next()) {
strMyString = r5.getString("countless");
}
return strMyString;
}
%>
<%!
private String doSomthing() throws java.sql.SQLException, ClassNotFoundException {
Connection conn2 = null;
String strMyString = "";
Class.forName("oracle.jdbc
conn2 = DriverManager.getConnectio
"jdbc:oracle:thin:@divodb0
"public_gdlp",
"public");
ResultSet r5;
String udc = "Select udc FROM public_gdlp.udc where treeid = 2 and udcseq = 1";
Statement stmt2 = conn2.createStatement();
r5 = stmt2.executeQuery(udc);
while (r5.next()) {
strMyString = r5.getString("countless");
}
return strMyString;
}
%>
<%!
public String doSomthing() {
Connection conn2 = null;
String strMyString = "";
try {
Class.forName("oracle.jdbc .driver.Or acleDriver ");
conn2 = DriverManager.getConnectio n(
"jdbc:oracle:thin:@divodb0 02:1521:sa lest01",
"public_gdlp",
"public");
ResultSet r5;
String udc = "Select udc FROM public_gdlp.udc where treeid = 2 and udcseq = 1";
Statement stmt2 = conn2.createStatement();
r5 = stmt2.executeQuery(udc);
while (r5.next()) {
strMyString = r5.getString("countless");
}
}
catch(SQLException e) {
System.out.println("SQLExc eption: " + e.getMessage());
}
catch(ClassNotFoundExcepti on cnfe) {
System.out.println("ClassN otFoundExc eption: " + cnfe.getMessage());
}
catch(Exception e1) { //this is the mother of all Exception..... nobody can bypass this one..:-)
System.out.println("Genera lException : " + e1.getMessage() );
}
return strMyString;
}
%>
public String doSomthing() {
Connection conn2 = null;
String strMyString = "";
try {
Class.forName("oracle.jdbc
conn2 = DriverManager.getConnectio
"jdbc:oracle:thin:@divodb0
"public_gdlp",
"public");
ResultSet r5;
String udc = "Select udc FROM public_gdlp.udc where treeid = 2 and udcseq = 1";
Statement stmt2 = conn2.createStatement();
r5 = stmt2.executeQuery(udc);
while (r5.next()) {
strMyString = r5.getString("countless");
}
}
catch(SQLException e) {
System.out.println("SQLExc
}
catch(ClassNotFoundExcepti
System.out.println("ClassN
}
catch(Exception e1) { //this is the mother of all Exception..... nobody can bypass this one..:-)
System.out.println("Genera
}
return strMyString;
}
%>
ASKER
That code you worked fine. But now if I try to change the system.out.println to out.println it tells me that the variable "out" is not a variable in the class
the out is not available in methods defined in jsp page. try the code I posted above. there is no point to catch an exception and just display it, the server will do that for you. you'll be better of using a jsp error page, that will come later.
for now, just throw the exception as I told you.
for now, just throw the exception as I told you.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Ooops...
this time I got slow in typing....:-)
this time I got slow in typing....:-)
post your code and we shd be able to help you out