JDBC没有从本地数据库中提取数据

时间:2018-10-02 07:21:22

标签: java jdbc derby

我正在尝试连接本地数据库。但这没做。我正在使用NetBeans IDE.Pls,请帮助我解决此问题。它会编译并说“ Build成功”,但是没有输出。

public class JDBCProject1 {

public static void main (String[] args){
  try
{
    //2. load / register Driver Manager
    Class.forName("org.apache.derby.jdbc.EmbeddedDriver");

    //3. establish connecction

    Connection conn = DriverManager.getConnection("jdbc:derby://localhost:1527/JDBC","Project1","Project1");
    System.out.println("Hello");

    //4. prepare statement
    Statement stmt = conn.createStatement();



    //5. execute statement

    ResultSet rs = stmt.executeQuery("select * from employees");

    //6. process the result

    while(rs.next())
    {
        int eid = rs.getInt("employeeNumber");
        String ename = rs.getString("lastName");
        //int sal = rs.getInt("salary");
        System.out.println("empid\t"+eid);
        System.out.println("empname\t"+ename);
        //System.out.println("empsalary\t"+sal);

    }


    //7. close connections

    rs.close();
    stmt.close();
    conn.close();
}
catch(Exception e)

{



}

}

}

我正在尝试连接本地数据库。但这没做。我正在使用NetBeans IDE.Pls,请帮助我解决此问题。它会编译并说“ Build成功”,但是没有输出。

0 个答案:

没有答案