I have the following Java code: (the parameters are the login data aswell as the query for the database)
public static String connectDB(String configFile, String query) throws FileNotFoundException, IOException, SQLException, ClassNotFoundException {
Properties p = new Properties();
p.load(new FileInputStream(configFile));
String serverName = (p.getProperty("RMS_DBServerName"));
String portNumber = (p.getProperty("DB_PortNumber"));
String sid = (p.getProperty("RMS_SID"));
String url = "jdbc:oracle:thin:@//" + serverName + ":" + portNumber + "/" + sid;
String username = (p.getProperty("RMS_Username"));
String password = (p.getProperty("RMS_Password"));
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection connection = DriverManager.getConnection(url, username, password);
try {
Statement stmt = connection.createStatement();
try {
ResultSet rset = stmt.executeQuery(query);
try {
while (rset.next()) {
System.out.println(rset.getString(1));
}
} finally {
try {
rset.close();
} catch (Exception ignore) {
}
}
return rset;
} finally {
try {
stmt.close();
} catch (Exception ignore) {
}
}
} finally {
try {
connection.close();
} catch (Exception ignore) {
}
}
}
The code is supposed to get the one cell from the database. The query works when the result is given to the console. But I want to return the cell from the method to another method in order to automate the process. But the return is returning code like this: jdbc:oracle:OracleDriver#........ . So can anyone help to fix this, I just want to return one cell that contains a number.
String, but yet you are returning a (closed!)ResultSet. Does not make any sense to me.