DERBY中的连接错误 [英] connectivity error in DERBY

查看:320
本文介绍了DERBY中的连接错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用derby数据库在eclipse中使用我的以下代码,但得到的错误为

i am using my following code in eclipse using derby database,but getting the error as

Insufficient data while reading from the network - expected a minimum of 6 bytes and received only 0 bytes.  The connection has been terminated.
    at org.apache.derby.client.am.SQLExceptionFactory40.getSQLException(Unknown Source)
    at org.apache.derby.client.am.SqlException.getSQLException(Unknown Source)
    at org.apache.derby.jdbc.ClientDriver.connect(Unknown Source)
    at java.sql.DriverManager.getConnection(DriverManager.java:322)
    at java.sql.DriverManager.getConnection(DriverManager.java:273)
    at jdbc.JDBCSample.main(JDBCSample.java:19)."       

软件包jdbc;

import java.sql.*;

public class JDBCSample {

public static void main( String args[]) {

String connectionURL = "jdbc:derby://127.0.0.1:8080/SAMPLE";
// Change the connection string according to your db, ip, username and password

try {

    // Load the Driver class.
    Class.forName("org.apache.derby.jdbc.ClientDriver");
    // If you are using any other database then load the right driver here.

    //Create the connection using the static getConnection method
    Connection con = DriverManager.getConnection (connectionURL);

    //Create a Statement class to execute the SQL statement
    Statement stmt = con.createStatement();

    //Execute the SQL statement and get the results in a Resultset
    ResultSet rs = stmt.executeQuery("select moviename, releasedate from movies");


    // Iterate through the ResultSet, displaying two values
    // for each row using the getString method

    while (rs.next())
        System.out.println("Name= " + rs.getString("moviename") + " Date= " + rs.getString("releasedate"));
    con.close();

}
catch (SQLException e) {
    e.printStackTrace();
}
catch (Exception e) {
    e.printStackTrace();
}
finally {


}
}
}

推荐答案

我认为,如果您的问题得到解决, 使用用户名和密码调用getConnection("..", "..", "..")方法. 例子

I think your problem will be solved, if you call getConnection("..", "..", "..") method with username and password. Example

Connection con = DriverManager.getConnection(connectionURL, "sa", "sa");

这篇关于DERBY中的连接错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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