0
I would like to limit a time for the connection. Every time she doesn’t find the Host to connect, she keeps trying and it takes.
Here’s the code:
@SuppressLint("NewApi")
public Connection CONN() {
/*Properties props = new Properties();
props.setProperty("user", "dbuser");
props.setProperty("password", "dbpassword");
props.setProperty(OracleConnection.CONNECTION_PROPERTY_THIN_NET_CONNECT_TIMEOUT, "2000");*/
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
.permitAll().build();
StrictMode.setThreadPolicy(policy);
Connection conn = null;
String ConnURL = null;
try {
Class.forName(classs);
ConnURL = "jdbc:jtds:sqlserver://" + ip + ";"
+ "databaseName=" + db + ";user=" + un + ";password="
+ password + ";namedPipe=true;loginTimeout=5;socketTimeout=1";
/*Properties properties = new Properties();
properties.put("connectTimeout", "2000");*/
DriverManager.setLoginTimeout(5);
conn = DriverManager.getConnection(ConnURL);
} catch (SQLException se) {
Log.e("ERRO", se.getMessage());
} catch (ClassNotFoundException e) {
Log.e("ERRO", e.getMessage());
} catch (Exception e) {
Log.e("ERRO", e.getMessage());
}
return conn;
}
While this link may answer the question, it is best to include the essential parts of the answer here and provide the link for reference. Replies per link only can be invalidated if the page with the link is changed. - Of Revision
– Isac
Yes sry, while I was also looking for a solution by reading http://jtds.sourceforge.net/faq.html I found a solution that worked well for me, by way of a response.
– Camadas
Why -1 after adding the answer ?! does what the OP wants -.-
– Camadas