-1

我试图连接到 mysql 数据库并操作其中的数据但是当我尝试运行我的代码时它得到错误,驱动程序 [java 应用程序] C:\program files\java\jre 1.8.0_111\bin\javaw.exe from我一直在阅读它,因为它启动 javaw 而不是 java.exe,但我似乎无法弄清楚如何切换到它,任何人都可以帮助我吗?

package jdbc;

import java.sql.*;
public class Driver {

public static void main(String[] args) {

    try
    {
        //get a connection to the database
        Connection myConn = DriverManager.getConnection("jdbc:mysql://localhost:3306/cs160test"); 
        //create a statement
        Statement myStmt = myConn.createStatement();
        //execute the sql query
        ResultSet myRs = myStmt.executeQuery("select * from genre");
        //process the result set
        while(myRs.next())
        {
            System.out.println(myRs.getString("name"));
        }
    }

    catch(Exception exc)
    {
        exc.printStackTrace();
    }

}

}

4

2 回答 2

0

确保保存所有类,包括具有 main 方法的类。如果这不起作用,请关闭 Eclipse 并重新打开它。

于 2020-04-21T19:34:50.703 回答
0

那没有错误。它告诉您您的程序exited,因为没有进一步的说明可遵循。

<terminated> main [java application] path\bin\javaw.exe

我重现了这种行为,发生这种情况的唯一方法是您的genre没有记录

于 2016-12-01T02:36:31.017 回答