【问题标题】:eclipse does not show any outputeclipse不显示任何输出
【发布时间】:2015-12-02 21:55:33
【问题描述】:

我使用 JDBC 在 java 上编写了非常简单的数据库查询。 这是代码

import java.sql.*;
public class statement {
    static final String JDBC_DRIVER="com.mysql.jdbc.Driver";
    static final String URL="jdbc:mysql://localhost/emp";
    static final String USER="root";
    static final String PAS="1234";
    public static void main(String [] args){
        System.out.println("hello");
        Connection con=null;
        Statement stmt=null;
        try{
            System.out.println("creating database connection");
            con=DriverManager.getConnection(URL,"root","1234");
            String sql="update Employee set age 30 where id =103";
            stmt=con.createStatement();
            Boolean ret=stmt.execute(sql);
            System.out.println("return value is: "+ret.toString());
            int rows=stmt.executeUpdate(sql);
            System.out.println("rows impacted: "+rows);
            stmt.close();
            con.close();
        }catch(SQLException se)
        {
            System.out.println("hello");
        }
    }

}

在我的最后一次捕获中 - 它只是检查程序是否输出任何内容。没有错误,也没有给出警告。但是,在我的控制台窗口上,我得到了

0 items 

消息。有什么问题?

附言我将所有 jar 文件都包含到我的项目中

【问题讨论】:

  • 你试过调试吗?你没有得到第一个“你好”来打印吗?
  • 打印0 items的代码在哪里?
  • 在控制台,什么都没有打印出来,这就是问题
  • 你不应该得到那个 SQL UPDATE 语句的错误吗?应该是 update Employee set age = 30 where id = 103
  • 不,我更正了,但控制台上有相同的 0 个项目

标签: java eclipse jdbc


【解决方案1】:

你能告诉我们你在命令行上输入了什么或者你是如何运行它的吗?

我将它剪切/粘贴到 Eclipse 中,而不是缺少 }。我得到了:

hello
creating database connection
hello

第二个 hello 表示引发了 SQLException,因为我的工作站上没有运行数据库。 我在想也许你真的没有正确的 java 命令。

【讨论】:

  • 不知道怎么粘贴图片。我在通常显示输出的选项卡上收到消息 0 项
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-10-26
  • 2016-07-28
  • 2015-02-22
  • 2019-02-13
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多