I have a Enum class named Status. I have a table of “servers” that I would like to show the Status of them in the table output.
When I run a while loop, and perform a result set, it does not recognise the Enum reference variable when I try to retrive data from the row which has the Enum values.
This line is the issue im referring to –
Status status;
status = rs.getString(“status”);
I get error “Type mismatch: cannot convert from String to Status”. How do I get it work?
public void pingServer(String theServerId) throws Exception{
Connection myCon = null;
PreparedStatement myStmt = null;
PreparedStatement myStmt2 = null;
ResultSet rs = null;
InetAddress inet = null;
String ip;
Status status = null;
// String s = status.getStatus();
Servers server = null;
try {
int serverId = Integer.parseInt(theServerId);
//get db connection
myCon = dataSource.getConnection();
//create sql to ping server
String sql = "select * from heartbeat.nodes";
String sql2 = "UPDATE heartbeat.nodes SET status = ? WHERE (nodeId = ?)";
//
myStmt = myCon.prepareStatement(sql);
myStmt2 = myCon.prepareStatement(sql2);
myStmt.setObject(1, status.getStatus());
myStmt.setInt(2, server.getNodeId());
rs = myStmt.executeQuery(sql);
while(rs.next()) {
ip = rs.getString("ipAddress");
inet = InetAddress.getByName(ip);
serverId = rs.getInt("nodeId");
status = rs.getString("status");
if(inet.isReachable(100)) {
server.setStatus(Status.SERVER_UP);
myStmt2.executeUpdate();
} else {
server.setStatus(Status.SERVER_DOWN);
myStmt2.executeUpdate();
This line is the issue im referring to –
Status status;
status = rs.getString(“status”);
I get error “Type mismatch: cannot convert from String to Status”. Does it need converting ? if so how do you convert Enums.