小鸟请各位大侠帮忙,一个比较小白的问题.
我写了一个插入数据库的代码,是用BEAN弄的,但是有错误,请各位帮忙看看;
错误提示:The method executeInsert(String) in the type conn is not applicable for the arguments (String, String, String, String, String)
页面中的代码:
<%
conn cctv = new conn();//创建一个对像以cctv
%>
<%
String name,sex,email,subject,memo;
name=request.getParameter( "name ");
sex=request.getParameter( "sex ");
email=request.getParameter( "email ");
subject=request.getParameter( "subject ");
memo=request.getParameter( "memo ");
cctv.executeInsert(name,sex,email,subject,memo);
response.sendRedirect( "xs.jsp ");
%>
bean中的插入方法:
public int executeInsert(String name,String sex,String email,String subject,String memo)
{
try
{
con = DriverManager.getConnection(url,user,password);
Statement stmt = con.createStatement();
int tiao=stmt.executeUpdate( "insert into book(name,sex,email,subject,memo) values( ' "+name+ " ', ' "+sex+ " ', ' "+email+ " ', ' "+subject+ " ', ' "+memo+ " ') ");
return tiao;
}
catch(
SQLException e)
{
System.out.println(e.getMessage());
}
return 0;
}
小弟就是像把SQL语误放在BEAN里,在页面中经量少有JAVA的代码!请各位帮忙,问下错在那里?
------解决方案--------------------你看看那条语句在sql中能运行成功么
还有 推荐你使用preparedStatement 防止sql注入
------解决方案--------------------cctv 把错误贴出来
------解决方案--------------------String name,sex,email,subject,memo;
改为
String name=null;
String sex=null;
String email=null;
String subject=null;
String memo=null;
------解决方案--------------------sql语句的问题吧.SYSTEM.OUT.PRINTLN();一下.看正确否?
------解决方案--------------------同lingar
String name,sex,email,subject,memo;
改为
String name = " ", sex = " ",email = " ", subject = " ", memo = " ";