报出上面那个错误应该怎么解决呢,急求!!!
程序:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class TestPrepareStatement {
public static void main(String[] args){
ResultSet rs=null;
Statement stmt=null;
Connection conn=null;
PreparedStatement pstmt=null;
try{
Class.forName("com.mysql.jdbc.Driver");
conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/yuangong","root","");
stmt=conn.createStatement();
pstmt=conn.prepareStatement("insert into yuangongbiao values(?,?,?,?,?)");
/*添加的第一条记录*/
pstmt.setInt(1, 1004);
pstmt.setString(2, "Lily");
pstmt.setString(3, "Lily@126.com");
pstmt.setInt(4, 3600);
pstmt.setString(5, "1999-02-13");
/*添加的第二条记录*/
pstmt.setInt(1, 1005);
pstmt.setString(2, "Li");
pstmt.setString(3, "Li@126.com");
pstmt.setInt(4, 3200);
pstmt.setString(5, "1979-02-13");
/*添加的第三条记录*/
pstmt.setInt(1, 1006);
pstmt.setString(2, "Wang");
pstmt.setString(3, "Wang@126.com");
pstmt.setInt(4, 3000);
pstmt.setString(5, "1994-02-13");
pstmt.executeQuery();
rs=stmt.executeQuery("select * from yuangongbiao");
while(rs.next()){
System.out.print(rs.getInt("employee_id"));
System.out.print(rs.getString("name"));
System.out.print(rs.getString("email"));
System.out.print(rs.getInt("salaty"));
System.out.print(rs.getString("birthday"));
}
}catch(ClassNotFoundException e){
e.printStackTrace();
}catch(SQLException e){
e.printStackTrace();
}finally{
try{
if(rs!=null){
rs.close();
rs=null;
}
if(pstmt!=null){
pstmt.close();
pstmt=null;
}
if(stmt!=null){
stmt.close();
stmt=null;
}
if(conn!=null){
conn.close();
conn=null;
}
}catch(SQLException e){
e.printStackTrace();
}
}
}
}
相关分类