-
Doubt
public List getEventKeys() throws SQLException, UnknownHostException {
PreparedStatement getEventKeys = null;
ResultSet rs = null;
try {
//get the host
String hostName = InetAddress.getLocalHost().getHostName();
String sql = "select event_key from event_trigger where" +
"EXISTS (SELECT VALUE FROM CONTROL_PARAM WHERE UPPER(KEY) = 'ACTIVESERVER'" +
"AND VALUE = ?)";
List eventKeys = new ArrayList();
getEventKeys = conn.prepareStatement(sql);
getEventKeys.setString(1,hostName);
rs = getEventKeys.executeQuery(sql);
while (rs.next()) {
eventKeys.add(rs.getInt("event_key"));
}
return eventKeys;
} finally {
//close statement and result set
getEventKeys.close();
rs.close();
}
__________________________________________________ _____________
Getting a null pointer exception at -rs.close-
and rs = getEventKeys.executeQuery(sql); does not excecute..
what could be the prob
-
Ideally you would get a null pointer exception there when there is no rs object for Java to close.
So a simple check would solve the issue.
Code:
if (rs != null) {
rs.close();
}
You are not having any results in your rs, so you are getting this exception. If the results should be there, then there is something wrong with your query.
PS: Please name your topics better. Doubt is not a nice name ;)
-
Try this
Code:
public List getEventKeys() throws SQLException, UnknownHostException {
PreparedStatement getEKeys = null;
ResultSet rs = null;
Connection locCon = null;
List eventKeys = new ArrayList();
try {
//get the host
String hostName = InetAddress.getLocalHost().getHostName();
String sql = "select event_key from event_trigger where" +
"EXISTS (SELECT VALUE FROM CONTROL_PARAM WHERE UPPER(KEY) = 'ACTIVESERVER'" +
"AND VALUE = ?)";
getEKeys = locCon.prepareStatement(sql);
getEKeys.setString(1,hostName);
rs = getEKeys.executeQuery(sql);
while (rs.next()) {
eventKeys.add(rs.getInt(1));
}
return eventKeys;
}
finally {
if (rs != null) {
rs.close();
}
if (getEKeys != null) {
getEKeys.close();
}
}
-
do we have to intialize the connection resultset and prepared statement..
it is showing an error.. and askin to initalize
-
yeah i think it is better to do that..
Code:
PreparedStatement getEKeys = null;
ResultSet rs = null;
Connection locCon = null;
-
no dude.. not working..!!
i guess connection cannot be initailized to null.. so i still point to the global connection established..!!
but even then, i don not manage to get a result in the result set..
:mad::mad::mad:
-
May be you can just say
Code:
Connection locCon = new Connection();
Then we can be sure the global thing is not causing any problem if it still does not work
-
I tried the global connection... and all the rest of the things remain the same..
i change just the sql to a simple select statement.. and it works fine..!!
now somethings wrong wit that sql and passing a parameter to the sql.. is that correct??
-
yes, that could be it. nice catch btw...
when you debug the program in eclipse or netbeans, just before the executeQuery statement is passed, see what is the value stored in the string variable sql..
copy that value and run it in sql editor or some program and see if you get a result.. this will help you identify if the query is correct or not..
-
the issue is still not resolved..!!
as i said its something seriosulsy to do witht he sql.. but the sql executes perfectly on the sql editor. whereas on the program it jsut spits out errors..
the excetion that i got this time on with the actuall sql was..
ORA-03115: unsupported network datatype or
representation
but its got nothin to do with the DB version adn criver version as it seems to be...
i simply replace the sql again with the simple select stmt.. i am able to get thru..
but why isnt the original one wrking..??
:mad::mad::confused::confused::(
-
missed the damn \n after the query end of line
instead of this -->
String sql = "select event_key from event_trigger where" +
"EXISTS (SELECT VALUE FROM CONTROL_PARAM WHERE UPPER(KEY) = 'ACTIVESERVER'" +
"AND VALUE = ?)";
it had to be this -->
String sql = "select event_key from event_trigger where \n" +
"EXISTS (SELECT VALUE FROM CONTROL_PARAM WHERE UPPER(KEY) = 'ACTIVESERVER' \n" +
"AND VALUE = ?)";
damn..!!:eek::eek:
-
You don't need the '\n' at the end of the lines, but you do need some whitespace. Your SQL would have looked like this:
"whereEXISTS" and "'ACTIVESERVER'AND"