如何在eclipse(part2)中配置javadb? [英] How to configure javadb in eclipse(part2)?

查看:105
本文介绍了如何在eclipse(part2)中配置javadb?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我以前的问题的延续如何在eclipse中配置javadb?一>。我能够对我的代码进行一些更改,但现在它给我这个错误 - > 错误:java.net.ConnectException:连接到端口1527上的服务器本地主机错误消息连接拒绝:连接错误。希望你们可以帮助我这个。



这是我的代码:

  import java.sql.Connection; 
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class Test {

public static void main(String [] args){
try {
Class.forName(org.apache。 derby.jdbc.ClientDriver)的newInstance();
} catch(InstantiationException e){
e.printStackTrace();
} catch(IllegalAccessException e){
e.printStackTrace(); X-454545454545 X-4545 X-4545 X-4545 X- 20045 X-454545 X-4545 X- 20045 X-454545 X- 20045 X-
}

final String DB_URL =jdbc:derby:// localhost:1527 / CoffeeDB; create = true;

try {
Connection conn = DriverManager.getConnection(DB_URL);
语句stmt = conn.createStatement();

String sql =(CREATE TABLE Coffee(Description CHAR(25),ProdNum CHAR(10)NOT NULL PRIMARY KEY,Price DOUBLE));
stmt.execute(sql);

sql =INSERT INTO咖啡值('玻利维亚黑暗','14-001',8.95);
stmt.executeUpdate(sql);

sql =INSERT INTO咖啡值('Bolivian Medium','14-002',8.95);
stmt.executeUpdate(sql);

sql =INSERT INTO Coffee VALUES('Brazilian Dark','15-001',7.95);
stmt.executeUpdate(sql);

sql =INSERT INTO Coffee VALUES('Brazilian Medium','15-002',7.95);
stmt.executeUpdate(sql);

sql =INSERT INTO咖啡值(巴西Decaf,15-003,8.55);
stmt.executeUpdate(sql);

sql =INSERT INTO咖啡值(中美洲黑人,'16-001',9.95);
stmt.executeUpdate(sql);

sql =INSERT INTO咖啡值(中美洲中等,16-002,9.95);
stmt.executeUpdate(sql);

sql =INSERT INTO Coffee VALUES('Sumatra Dark','17-001',7.95);
stmt.executeUpdate(sql);

sql =INSERT INTO Coffee VALUES('Sumatra Decaf','17-002',8.95);
stmt.executeUpdate(sql);

sql =INSERT INTO Coffee VALUES('Sumatra Medium','17-003',7.95);
stmt.executeUpdate(sql);

sql =INSERT INTO咖啡值('Sumatra Organic Dark','17-004',11.95);
stmt.executeUpdate(sql);

sql =INSERT INTO咖啡值('Kona Medium','18-001',18.45);
stmt.executeUpdate(sql);

sql =INSERT INTO Coffee VALUES('Kona Dark','18-002',18.45);
stmt.executeUpdate(sql);

sql =INSERT INTO Coffee VALUES('French Roast Dark','19-001',9.65);
stmt.executeUpdate(sql);

sql =INSERT INTO咖啡值('Galapagos Medium','20-001',6.85);
stmt.executeUpdate(sql);

sql =INSERT INTO咖啡值('危地马拉黑暗','21-001',9.95);
stmt.executeUpdate(sql);

sql =INSERT INTO咖啡值('危地马拉十佳'''21-002',10.45);
stmt.executeUpdate(sql);

sql =INSERT INTO咖啡值('危地马拉中等','21-003',9.95);
stmt.executeUpdate(sql);

String sqlStatement =SELECT描述FROM Coffee;
ResultSet result = stmt.executeQuery(sqlStatement);

System.out.println(在数据库中找到的咖啡);
System.out.println(-----------------------------);

while(result.next()){
System.out.println(result.getString(Description));
}

conn.close();
} catch(Exception ex){
System.out.println(ERROR:+ ex.getMessage());
}

}

}


解决方案

我一直在尝试使用您当前的代码,发现异常在服务器未启动时发生。解决这个问题的方法是以简单的方式启动服务器:



转到derby服务器下载的提取文件夹中的lib文件夹,通过命令提示符。对我来说如下:

  C:\> cd opt\db-derby-10.11.1.1-lib \lib 

C:\opt\db-derby-10.11.1.1-lib\lib> java -jar derbyrun.jar服务器启动
Sat Oct 03 16:26: 29 IST 2015:使用基本服务器安全策略安装的安全管理员。
Sat Oct 03 16:26:29 IST 2015年:Apache Derby网络服务器 - 10.11.1.1 - (1616546)启动并准备接收端口1527上的连接

有一种不同的方法可以在Eclipse中启动服务器。您将需要安装插件,然后启动服务器。以下参考资料可以帮助您:



Derby插件如何


this is the continuation of my previous question How to configure javadb in eclipse?. I was able to made some changes on my code but now it is giving me this error -> ERROR: java.net.ConnectException : Error connecting to server localhost on port 1527 with message Connection refused: connect. Hope you guys can help me with this one.

Here is my code:

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class Test {

public static void main(String[] args) {
    try {
        Class.forName("org.apache.derby.jdbc.ClientDriver").newInstance();
    } catch (InstantiationException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }

    final String DB_URL = "jdbc:derby://localhost:1527/CoffeeDB;create=true";

    try{
        Connection conn = DriverManager.getConnection(DB_URL);
        Statement stmt = conn.createStatement();

        String sql = ("CREATE TABLE Coffee(Description CHAR(25),ProdNum CHAR(10) NOT NULL PRIMARY KEY,Price DOUBLE)");
        stmt.execute(sql);

        sql = "INSERT INTO Coffee VALUES('Bolivian Dark','14-001',8.95)";
        stmt.executeUpdate(sql);

        sql = "INSERT INTO Coffee VALUES('Bolivian Medium','14-002',8.95)";
        stmt.executeUpdate(sql);

        sql = "INSERT INTO Coffee VALUES('Brazilian Dark','15-001',7.95)";
        stmt.executeUpdate(sql);

        sql = "INSERT INTO Coffee VALUES('Brazilian Medium','15-002',7.95)";
        stmt.executeUpdate(sql);

        sql = "INSERT INTO Coffee VALUES('Brazilian Decaf','15-003',8.55)";
        stmt.executeUpdate(sql);

        sql = "INSERT INTO Coffee VALUES('Central American Dark','16-001',9.95)";
        stmt.executeUpdate(sql);

        sql = "INSERT INTO Coffee VALUES('Central American Medium','16-002',9.95)";
        stmt.executeUpdate(sql);

        sql = "INSERT INTO Coffee VALUES('Sumatra Dark','17-001',7.95)";
        stmt.executeUpdate(sql);

        sql = "INSERT INTO Coffee VALUES('Sumatra Decaf','17-002',8.95)";
        stmt.executeUpdate(sql);

        sql = "INSERT INTO Coffee VALUES('Sumatra Medium','17-003',7.95)";
        stmt.executeUpdate(sql);

        sql = "INSERT INTO Coffee VALUES('Sumatra Organic Dark','17-004',11.95)";
        stmt.executeUpdate(sql);

        sql = "INSERT INTO Coffee VALUES('Kona Medium','18-001',18.45)";
        stmt.executeUpdate(sql);

        sql = "INSERT INTO Coffee VALUES('Kona Dark','18-002',18.45)";
        stmt.executeUpdate(sql);

        sql = "INSERT INTO Coffee VALUES('French Roast Dark','19-001',9.65)";
        stmt.executeUpdate(sql);

        sql = "INSERT INTO Coffee VALUES('Galapagos Medium','20-001',6.85)";
        stmt.executeUpdate(sql);

        sql = "INSERT INTO Coffee VALUES('Guatemalan Dark','21-001',9.95)";
        stmt.executeUpdate(sql);

        sql = "INSERT INTO Coffee VALUES('Guatemalan Decaf','21-002',10.45)";
        stmt.executeUpdate(sql);

        sql = "INSERT INTO Coffee VALUES('Guatemalan Medium','21-003',9.95)";
        stmt.executeUpdate(sql);

        String sqlStatement = "SELECT Description FROM Coffee";
        ResultSet result = stmt.executeQuery(sqlStatement);

        System.out.println("Coffees found in the Database");
        System.out.println("-----------------------------");

        while(result.next()){
            System.out.println(result.getString("Description"));
        }

        conn.close();
    }catch(Exception ex){
        System.out.println("ERROR: " + ex.getMessage());
    }

}

}

解决方案

I had been trying with your current code and found that the exception happens when the server is not being started. The way to solve this is start the server in a simple way:

Go to the lib folder in the extracted folder of derby server download over command prompt. For me it was as follows:

C:\>cd opt\db-derby-10.11.1.1-lib\lib

C:\opt\db-derby-10.11.1.1-lib\lib>java -jar derbyrun.jar server start
Sat Oct 03 16:26:29 IST 2015 : Security manager installed using the Basic server security policy.
Sat Oct 03 16:26:29 IST 2015 : Apache Derby Network Server - 10.11.1.1 - (1616546) started and ready to accept connections on port 1527

There is a different way by which you can start the server in Eclipse. You would need to install plugin and then start the server. The following references should help you:

Derby Plugin How To
Getting Started with Derby Plugin for Eclipse

这篇关于如何在eclipse(part2)中配置javadb?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆