【发布时间】:2016-10-23 13:24:03
【问题描述】:
我的应用程序使用了一个Mysql连接,它是使用这段代码获得的:
public static void Connect(){
try
{
Class.forName("com.mysql.jdbc.Driver").newInstance();
String url = "jdbc:mysql://" + host + ":" + port + "/"+ db;
ct = DriverManager.getConnection(url, user, pass);
st = ct.createStatement();
System.out.println("Csatlakozva....\n");
}
catch (InstantiationException e)
{
Main.textArea.setText("Error : Instantiation!");
//System.err.println("Error : Instantiation");
e.printStackTrace();
}
catch (IllegalAccessException e)
{
Main.textArea.setText("Error : Illegális Behatolás!");
//System.err.println("Error : Illegális Behatolás!");
e.printStackTrace();
}
catch (ClassNotFoundException e)
{
Main.textArea.setText("Error : Class Nem Található!");
//System.err.println("Error : Class Nem Található!");
e.printStackTrace();
}
catch (SQLException e)
{
Main.textArea.setText("Error : Adatbázis Nem Található!");
//System.err.println("Error : Adatbázis Nem Található!");
e.printStackTrace();
}
}
如果 MySQL 数据库服务器未运行,因此我的应用无法打开连接,如何让我的应用等待连接建立?
【问题讨论】:
-
您可以在代码中添加注释以显示等待的位置吗?这是本地还是远程 MySQL 实例?你用的是什么操作系统?
-
那么,您的确切问题是什么?你想发生什么?
-
@Michael Markidis 我想要做的是......有我的连接代码......我想要如果mysql没有运行所以我的应用程序无法打开连接,我的应用程序必须等待连接做某事。
标签: java mysql swing connection wait