sparafucile17
Programmer
Ok, here's the deal: I want to try to open a database but want to know if the connection was successful or not. But the only way I know that it wasn't successful is that a sql exception is fired. So I was thinking that I could use a bool to keep track of connection status like so:
boolean isConnected;
try
{
DriverManager.getConnection("jdbc:codebase:192.168.0.1:1583/CodebaseODBC", "User", "Pass"
isConnected = true;
}
catch (Exception e)
{
JOptionPane.showMessageDialog(null, "Cannot connect!"
isConnected = false;
}
My worry here is that the isConnected=true; statement will be executed regardless of exceptions. Is this hunch correct? I'm a little clueless when it comes to the try-catch command.
If this doesn't work, does anyone have any other ideas?
Regards,
Jeff
boolean isConnected;
try
{
DriverManager.getConnection("jdbc:codebase:192.168.0.1:1583/CodebaseODBC", "User", "Pass"
isConnected = true;
}
catch (Exception e)
{
JOptionPane.showMessageDialog(null, "Cannot connect!"
isConnected = false;
}
My worry here is that the isConnected=true; statement will be executed regardless of exceptions. Is this hunch correct? I'm a little clueless when it comes to the try-catch command.
If this doesn't work, does anyone have any other ideas?
Regards,
Jeff