java向Oracle数据库中插入数据时总是提示
importjava.sql.Connection;importjava.sql.DriverManager;importjava.sql.PreparedStateme...
import java.sql.Connection;import java.sql.DriverManager;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;import java.sql.Timestamp;public class CopyOfTestJDBC2 { public void getEmployees(int id, String name,int location,int leveis){ Connection conn = null; PreparedStatement pstmt = null; try { //(1)Class.forName()加载驱动 Class.forName("oracle.jdbc.driver.OracleDriver"); //(2)DriverManager.getConnection(URL,用户名,密码)获得数据库连接(Connection) conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:shop","shop_display","1234"); //(3)获得Statement对象,执行SQL语句 String sql = "insert into custom (id,name,location,leveis) VALUES (?,?,?,?)"; pstmt = conn.prepareStatement(sql); pstmt.setInt(1, id); pstmt.setString(2, name); pstmt.setInt(3, location); pstmt.setInt(4, leveis); int i = pstmt.executeUpdate(sql); if(i>0){ System.out.println("插入数据成功!"); } } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); }finally{ //释放资源 try { pstmt.close(); conn.close(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } public static void main(String[] args){ CopyOfTestJDBC2 co = new CopyOfTestJDBC2(); co.getEmployees(12,"三星",3,2); // TestJDBC tj = new TestJDBC();// tj.getEmployees(); }}上面这个是代码,图片里面是提示的错误信息和数据库的表的情况,新手刚学到数据库,愁死了,找了好几个小时的错误了,试了n遍都没弄明白到底哪错了
标题不知道为什么少字了,总是提示并非所有变量都已绑定 展开
标题不知道为什么少字了,总是提示并非所有变量都已绑定 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询