当前位置: 代码迷 >> Java相关 >> 插入错误,参数不足
  详细解决方案

插入错误,参数不足

热度:1260   发布时间:2013-02-25 21:48:39.0
插入异常,参数不足
import java.sql.*; 
import java.util.Scanner;
import java.lang.*;
public class InsertAndQuery{
  public static void main(String args[]){
  Connection con;
  Statement sql; 
  ResultSet rs;
   
  try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");  
  }
  catch(ClassNotFoundException e){
  System.out.println(""+e);
  }
  try{  
  Scanner input=new Scanner(System.in);
  System.out.print("请输入工号:");
  String number=input.nextLine();
  System.out.print("请输入姓名:");
  String name=input.nextLine();
  System.out.print("请输入出生日期:");
  String b=input.nextLine();
  Date birth=Date.valueOf(b);
  System.out.print("请输入工资:");
  Double salary=input.nextDouble();
  con=DriverManager.getConnection("jdbc:odbc:company","","");
  sql=con.createStatement();
  sql.executeUpdate
  ("INSERT INTO person VALUES(number,name,birth,salary)");
  rs=sql.executeQuery("SELECT * FROM person");
  while(rs.next()){
  number=rs.getString(1);
  name=rs.getString(2);
  birth=rs.getDate(3);
  salary=rs.getDouble(4);
  System.out.println(number+","+name+","+birth+","+salary);
  }
  con.close();
  }
  catch(SQLException e){
  System.out.println(e);
  }
  }
}


------解决方案--------------------------------------------------------
("INSERT INTO person VALUES(number,name,birth,salary)");


("INSERT INTO person VALUES("+number+","+name+","+birth+","+salary+")");
  相关解决方案