1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| public class ConnexionDB {
private Connection con;
public ConnexionDB() {
}
public Boolean connexion()
{
try {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
String driver = "net.sourceforge.jtds.jdbc.Driver";
Class.forName(driver).newInstance();
String conString = "jdbc:jtds:sqlserver://xxx.xxx.xxx.xxx:1433;databaseName=XXXXXX;";
String user = "xxxx";
String password = "********";
setCon(DriverManager.getConnection(conString, user, password));
return true;
}catch (Exception e){
return false;
}
}
public void closeConnexion()
{
try {
getCon().close();
} catch (SQLException e) {
e.printStackTrace();
}
}
public Connection getCon() {
return con;
}
public void setCon(Connection con) {
this.con = con;
}
} |
Partager