mirror of
https://github.com/HeidiSQL/HeidiSQL.git
synced 2026-03-13 09:24:25 +08:00
45 lines
1.1 KiB
Plaintext
45 lines
1.1 KiB
Plaintext
import com.mysql.jdbc.jdbc2.optional.*;
|
|
import javax.sql.DataSource;
|
|
|
|
DB db = null;
|
|
|
|
WindowContext context = argObj("windowContext");
|
|
Frame f = context.get("/");
|
|
HashObject profile = argObj("profile");
|
|
|
|
try
|
|
{
|
|
MysqlDataSource ds = new MysqlDataSource();
|
|
String url = String.format("jdbc:mysql://%s:%s/?zeroDateTimeBehavior=convertToNull&useOldAliasMetadataBehavior=true&useCompression=%s",
|
|
profile.get("host"), profile.get("port"), profile.get("compress"));
|
|
|
|
ds.setUrl(url);
|
|
ds.setUser(profile.get("user"));
|
|
ds.setPassword(profile.get("password"));
|
|
ds.setLoginTimeout(Integer.parseInt(profile.get("timeout")));
|
|
|
|
db = new DB((DataSource)ds);
|
|
db.execute("select 'abcdefg'");
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Throwable cause = e.getCause();
|
|
String message = cause.getMessage();
|
|
|
|
if (message.indexOf("\n") != -1)
|
|
{
|
|
int startMessage = message.indexOf("MESSAGE:");
|
|
if ( startMessage != -1)
|
|
{
|
|
startMessage+=8;
|
|
message = message.substring(startMessage, message.indexOf("\n", startMessage));
|
|
}
|
|
}
|
|
|
|
f.popupMessage("Connection Failed!", message);
|
|
db = null;
|
|
}
|
|
|
|
return db;
|
|
|