log para teste
DESCRIPTION
teteTRANSCRIPT
![Page 1: Log Para Teste](https://reader031.vdocuments.pub/reader031/viewer/2022020516/577c77571a28abe0548bb6a9/html5/thumbnails/1.jpg)
import java.io.IOException;import java.net.InetAddress;import java.net.UnknownHostException;import java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.Statement;import android.util.Log;public class SQLServer{
private static String TAG = "Banco Servidor";public Connection con;public Statement stmt;public ResultSet rs;private String DRIVER = "net.sourceforge.jtds.jdbc.Driver";public boolean testaConexao(String ip){
InetAddress in = null; try { in = InetAddress.getByName(ip); } catch (UnknownHostException e) {
e.printStackTrace(); }
try { if(in.isReachable(5000)){ Log.i(TAG,"Responde OK"); return true; } else{ Log.e(TAG,"No responde: Time out"); return false; } } catch (IOException e) { Log.e(TAG,e.toString()); }
return false;}public int OpenTeste(String serv,String porta,String database,String
user,String senha){String url = "jdbc:jtds:sqlserver://"+serv+":"+porta+"/"+database;try{
Class.forName(DRIVER);Log.e(TAG,""+DriverManager.getLoginTimeout());DriverManager.setLoginTimeout(5000);Log.e(TAG,""+DriverManager.getLoginTimeout());
con = DriverManager.getConnection(url, user, senha); Log.i(TAG,"Conexão Aberta com Sucesso"); return 0;}catch (Exception e) {
if (e.getMessage().equals("Network error IOException: localhost/127.0.0.1:1433 - Connection refused")){
return 1;}else{
Log.e(TAG,"Open "+e.getMessage());return 2;
}
![Page 2: Log Para Teste](https://reader031.vdocuments.pub/reader031/viewer/2022020516/577c77571a28abe0548bb6a9/html5/thumbnails/2.jpg)
}}public void Open(){
try{Class.forName(DRIVER);DriverManager.setLoginTimeout(-1);
con = DriverManager.getConnection(ParametroTemporario.URL, ParametroTemporario.USUARIO, ParametroTemporario.SENHA);
Log.i(TAG,"Conexão Aberta com Sucesso");}catch (Exception e) {
Log.e(TAG,"Open "+e);}
} public void Close() {
try{ Log.i(TAG,"Conexão Servidor Fechada");
}finally{ if(rs != null) try{ rs.close(); } catch(Exception ex){} if(stmt != null) try{ stmt.close(); } catch(Exception ex){} if(con != null) try{ con.close(); } catch(Exception ex){} }
}}