请教关于数据库插入记录的问题
在进行插入时总提示需要参数,是否SQL语句values时不能用形参,NO,name,level,salary在前面有定义并赋值了
try
{Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver ");}
catch(
ClassNotFoundException ce)
{System.out.println( "
SQLException: "+ce.getMessage());}
try
{Connection con=DriverManager.getConnection( "jdbc:odbc:empDB ");
Statement stmt=con.createStatement();
String sqlstr= "insert into employee values(NO,name,level,salary) ";//
stmt.executeUpdate(sqlstr);
stmt.close();
}
catch(SQLException e)
{System.out.println( "SQLException: "+e.getMessage());
}
------解决方案--------------------String sqlstr= "insert into employee values(NO,name,level,salary) ";//
假设NO,level,salary在数据库里是int类型,name是varchar类型.
这里应该改成
String sqlstr= "insert into employee values( "+NO+ ", ' "+name+ " ', "+level+ ", "+salary+ ") ";
------解决方案--------------------String sqlstr= "insert into employee values( ' "+NO+ " ', ' "+name+ " ', ' "+level+ " ', ' "+salary+ " ') ";
NO,name,level,salary在前面有定义并赋值了
还有中间有没有null