【发布时间】:2015-09-05 19:46:59
【问题描述】:
我想使用 select 关键字在 Java 中显示来自 Oracle 数据库的记录,但它不起作用。当我运行程序时,它会显示 SQL 命令,但不会显示我想要的结果。
我的代码是这样的:
static void modify()
{
System.out.println("Enter employee ID");
empid=sc.nextInt();
try{
con=Connection1.getConnection();
stmt=con.createStatement();
String d="select * from emp where empid='"+empid+"'";
rs=stmt.executeQuery(d);
System.out.println(""+d);
}
catch(SQLException e)
{
e.printStackTrace();
}
}
当我运行应用程序时,会显示此结果而不是数据库中的记录:
select * from emp where empid='14'
【问题讨论】:
-
你确定这是所有的代码吗?我什至看不到它将在哪里打印出 select 语句...我希望它是 toString 为 stmt 对象显示的任何内容...。您将需要遍历结果集并打印它给您的内容显示记录。
-
您正在打印 SQL 语句。但是您永远不会从
ResultSet对象中获取数据或显示该数据。所以你不会从数据库中看到任何信息。 -
在您的结果集中,表中的字段可以通过索引访问。