我想将derby DB连接到Java应用程序。我已经下载了所有的罐子,设置类路径作为Java目录,并下载Derby.What我得到现在是:java derby连接到服务器本地主机的错误1527
java.sql.SQLNonTransientConnectionException: java.net.ConnectException : Error connecting to server localhost on port 1527 with message Connection refused: connect.
谁能帮助我?这是什么实际上意味着,什么现在我做的我猜测Database_url变量可能存在问题,但我不知道如何设置它。
private static final String protocol = "jdbc:derby:";
public static void main(String[] args) throws ClassNotFoundException, IllegalAccessException, InstantiationException, SQLException {
final String DATABASE_URL = "jdbc:derby://localhost:1527/myDB;create=true;user=user;password=pass";
try {
Class.forName("org.apache.derby.jdbc.ClientDriver");
System.out.println("Loaded the client driver.");
} catch (Exception err) {
System.err.println("Unable to load the client driver.");
err.printStackTrace(System.err);
System.exit(0);
}
String dbName = "BookDatabase";
Connection conn = null;
try {
System.out.println(
"Connecting to and creating the database...");
conn = DriverManager.getConnection(DATABASE_URL);
System.out.println("Database created.");
Statement s = (Statement) conn.createStatement();
s.execute("CREATE TABLE names" +
"(author varchar(50), author_id " +
"int, url varchar(80))");
System.out.println("Created 'names' table.");
System.out.println("Inserting authors.");
s.execute("INSERT INTO names " +
"VALUES ('Adams, Douglas', 1," +
"'http://www.douglasadams.com')");
s.execute("INSERT INTO names " +
"VALUES ('Simmons, Dan', 2, 'http://www.dansimmons.com')");
s.execute("INSERT INTO names " +
"VALUES ('Stephenson, Neal', 3, " +
"'http://www.nealstephenson.com')");
System.out.println("Authors inserted.");
conn.close();
} catch (SQLException err) {
System.err.println("SQL error.");
err.printStackTrace(System.err);
System.exit(0);
}
}