首页 > 解决方案 > 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;
        }

标签: android-studio

解决方案


推荐阅读