类连接
我正在使用https://sourceforge.net/projects/jtds/files/jtds/1.2.7/
public class ConnectionDB {
String ip = "192.168.1.103";
String classs = "net.sourceforge.jtds.jdbc.Driver";
String db = "Andro";
String un = "abc";
String password = "1";
@SuppressLint("NewApi")
public Connection CONN() {
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 + ";";
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;
}
}
和班级登录
ConnectionDB con=new ConnectionDB();
if (!TextUtils.isEmpty(password) &&!TextUtils.isEmpty(email)) {
try {
if (con == null) {
alertDialog.setMessage("Cannot Access To Server");
} else {
String query = "Select * from Partner where lower(username)=lower('" + email + "') and password=N'" + password + "'";
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(query);
if (rs.next()) {
alertDialog.setMessage("Success");
} else {
alertDialog.setMessage("Fail");
}
}
} catch (Exception ex) {
z = "Exceptions";
}
}
我搜索了google,但没有找到答案 对不起,我的英语不好