The old way would look like this:
Code: Select all
sql="SELECT Username FROM Users";
var username="";
// Get the path for the selected menu item from the DB
var con=system.getDatabaseConnection("DBCONNECTION");
var rs,stmt;
try {
stmt=con.prepareStatement(sql);
rs=stmt.executeQuery();
while (rs.next()) {
username=rs.getString("Username");
}
} catch (e) {
// Dump the SQL for debugging purposes
print("An error occurred reading the database with the query " + sql);
print(e);
if(rs) rs.close();
if(stmt) stmt.close();
if(con) con.close();
event.stopExecution();
} finally {
if(rs) rs.close();
if(stmt) stmt.close();
if(con) con.close();
}
Code: Select all
services.database.executeSelectStatement("DBCONNECTION","SELECT Username FROM Users",
function (columnData) {
username=columnData.Username;
});
In other words, don't declare any local variables inside of the function.