android-studio - DriverManager.getConnection("wholeurlthatshouldwork") 抛出 SQLexeption,对于一个代码它的工作,而对于第二个它不
问题描述
就像我写的那样,我的一个程序运行良好,但第二个程序却不能正常运行。尝试使用 DriverManager.getConnection() 时出现问题。使用调试器时,我可以看到它直接进入 SQLexeption。它并没有真正尝试开始。配置:
@SuppressLint("NewApi")
public Connection connectionclass(String user, String password, String database, String server) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
Connection connection = null;
String ConnectionURL = null;
try {
Class.forName("net.sourceforge.jtds.jdbc.Driver");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
ConnectionURL = "jdbc:jtds:sqlserver://" + server + ";databaseName=" + database + ";user=" + user + ";password=" + password + ";";
try {
DriverManager.setLoginTimeout(1);
connection = DriverManager.getConnection(ConnectionURL);
} catch (SQLException e) {
e.printStackTrace();
}
return connection;
}
解决方案
推荐阅读
- c# - 将特定地址或端口分配给 WCF 服务
- python - 在 Python 中解析/处理巨大的 JSON 文件的有效方法是什么?
- php - JpGraph 免费开源替代品
- java - 原因:org.springframework.beans.factory.BeanCreationException:创建名为“mvcConversionService”的bean时出错
- javascript - 在单独的画布中渲染多个视频
- json - 如何在 ionic 3 中使用 ngx-translate 解决“ERROR SyntaxError: Unexpected token / in JSON at position 0”?
- sql - 我的查询从同一个表中提取数据,这导致输出显示空单元格。如何从我的输出中消除这些?
- wordpress - 如何使用 css、php 和 javascript 在 wordpress 中编辑网站
- express - 使用 nodemon nameofile.js 运行时,'nodemon' 未被识别为内部或外部命令
- java - Spring - Neo4j:当存在关系实体时,类属性返回 Null