0
我曾使用此代码将我的Android Studio连接到Microsoft SQL服务器。将Oracle DB与Android Studio项目连接的连接类
public class ConnectionClass
{
String ip = "192.168.1.4";
String classs = "net.sourceforge.jtds.jdbc.Driver";
String db = "BlackForestProd";
String un = "sa";
String password = "[email protected]";
@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;
}
}
使用的连接类的java文件,从数据库
connectionClass = new ConnectionClass();
Connection con = connectionClass.CONN();
if (con == null) {
z = "Error in connection with server";
} else {
Statement statement = con.createStatement();
rs = statement.executeQuery("select Name from tblAppcustomer where Mobile='" + userid + "'");
while (rs.next()) {
clientname = rs.getString("Name");
}
}
获取值同样地,我有我的Oracle数据库,我想在我的Android项目中使用的数据。有没有类似的方式来做到这一点。或者还有其他方法。我是Android的初学者。
请记住,每个人都可以提取应用中包含的用户名和密码。因此每个人都可以连接到数据库并根据使用的数据库凭证的权限读取/修改/删除数据。 – Robert