首页 文章

EOF错误,Java和Derby数据库

提问于
浏览
-2

我正在使用德比数据库创建一个日历 . 我已创建并插入数据库,但是在打印时;它会引发EOF错误 . 欢迎任何建议,这是有问题的方法 .

public void show() {
    try {
        ResultSet results = stm.executeQuery("select * from Users");
        while (results.next()) {
             //print result???
        }
    } catch (Exception e) {
        System.err.println(e.getMessage());
    }
}

这是堆栈跟踪:

语法错误:在第1行第167行遇到“” . 线程“main”中的异常java.lang.Error:未解析的编译

问题:PrintStream类型中的println(boolean)方法不适用于参数(void)

这是设置

public void populate() {
            try {
        stm.execute( "insert into Users values (User_ID, User_FirstName, User_LastName , AdminFlag, UserNamex, Passwordx"
                +                             "(12565, 'Elliot','Green','True' ,'elliot2','1234')");
public void createTable() {
    try {
        stm.execute("drop table User"); // May fail
    } catch (Exception e) { e.printStack();}

    String sql1 = "create table Users ( "
            + "  User_ID          Integer,"
            + "  User_FirstName   Varchar(50),    "
            + "  User_LastName    Varchar(50), " 
            + "  AdminFlag        Boolean, "
            + "  UserNamex        Varchar(50),  "   
            + "  Passwordx        Varchar(100) )";



    try
    {
        stm.execute("drop table Users");
    } 
    catch ( Exception e ) { e.printStackTrace(); }

    try {
        System.out.println("SQL sql1");
        stm.execute(sql1);
    } catch (Exception e) { e.printStackTrace(); System.exit(-1); // Give up 
    }
}

1 回答

  • 1

    来自您的pastebin的违规行如下:

    System.err.println(e.printStackTrace());
    

    e.printStackTrace()void 方法,因为它不返回任何内容 . 您无法将此方法的结果传递给 System.err.println(...) ,因为它没有意义:没有任何内容可以打印 .

    你应该写

    e.printStackTrace();
    

    代替 .

相关问题