运行时eclipse中的<terminated>错误

时间:2018-02-11 17:08:40

标签: java

enter image description here我想查看数据库的输出,但是当我运行它时,显示在控制台窗口中终止。该怎么办?它说main()方法无效,你可以在照片中看到,请帮忙。

以下是代码:

package demo1;

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

public class DataCon {

    public static void main(String[] args) {
        try {
            Class.forName("com.mysql.jdbc.Driver");
            Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/sonoo", "root", "");
            // here sonoo is database name, root is username and password
            Statement stmt = con.createStatement();
            ResultSet rs = stmt.executeQuery("select * from emp");
            while (rs.next())
                System.out.println(rs.getInt(1) + "  " + rs.getString(2) + "" + rs.getString(3));
            con.close();
        } catch (Exception e) {
            System.out.println(e);
        }
    }

}

0 个答案:

没有答案