【发布时间】: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 个项目