简单数据库应用程序发生“ IO错误:连接被拒绝(连接被拒绝)”拒绝

时间:2019-05-12 01:30:19

标签: java database-connection

此应用未按需向控制台显示数据库的任何结果。拒绝显示“ IO错误:连接被拒绝(连接被拒绝)”。

这不是防火墙问题(防火墙已关闭)。端口匹配且正确,服务器肯定已启动并正在运行。

 package javaapplication4;

 import java.sql.*;

 public class JavaApplication4  {

 public static void main(String[] args) {
   String data = "jdbc:derby://localhost:1527/sample";
   try (
       Connection conn = DriverManager.getConnection(
           data, "app", "APP");
       Statement st = conn.createStatement()) {

       Class.forName("org.apache.derby.jdbc.ClientDriver");

        ResultSet rec = st.executeQuery(
            "select CUSTOMER_ID, NAME, CITY, STATE " +
            "from APP.CUSTOMER " +
            "order by CUSTOMER_ID");
        while (rec.next()) {
            System.out.println("CUSTOMER_ID:\t"
                + rec.getString(1));
            System.out.println("NAME:\t" + rec.getString(2));
            System.out.println("CITY:\t" + rec.getString(3));
            System.out.println("STATE:\t" + rec.getString(4));
            System.out.println();
        }
        st.close();
    } catch (SQLException s) {
        System.out.println("SQL Error: " + s.toString() + " "
            + s.getErrorCode() + " " + s.getSQLState());
    } catch (Exception e) {
        System.out.println("Error: " + e.toString()
            + e.getMessage());
    }
     }
 }

该程序应在netbeans控制台中显示4个数据库记录的名称,城市和州。相反,它给出了先前描述的拒绝。

0 个答案:

没有答案