当前位置: 技术问答>java相关
method 的不兼容类型。无法将 java.lang.String 转换为 java.sql.ResultSet?
来源: 互联网 发布时间:2015-09-21
本文导语: 我用mysql和jsp做的一个留言本,一点提交就会转到insert.jsp,页面就显示:method 的不兼容类型。 无法将 java.lang.String 转换为 java.sql.ResultSet.我以前也遇到过这种情况,但一直没解决, 请问这句话是有什麽引起的呢?...
我用mysql和jsp做的一个留言本,一点提交就会转到insert.jsp,页面就显示:method 的不兼容类型。
无法将 java.lang.String 转换为 java.sql.ResultSet.我以前也遇到过这种情况,但一直没解决,
请问这句话是有什麽引起的呢?到底是哪个语句写错了会出现这个提示?我的insert.jsp和javabean如下所示:
/////////////insert.jsp///////////////////////////////
////////////////////////lyobean.java/////////////////////////////////////
package liren;
import java.sql.*;
public class lyobean{
ResultSet rs;
Statement stm;
Connection conn;
String name,email,title,content;
String sql="select * from li";
String query="insert into li values('"+name+"','"+email+"','"+title+"','"+content+"')";
public lyobean()throws SQLException{
try{
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
}catch(Exception e){
System.out.println("Can't conect the driver!");
}
}
public ResultSet executeQuery(ResultSet rs)throws SQLException{
rs=null;
conn=DriverManager.getConnection("jdbc:mysql//localhost/test","user=lyo","qijiashe");///我设置的mysql的密码///
stm=conn.createStatement();
rs=stm.executeQuery(sql);
return rs;
}
public void executeUpdate(String query)throws SQLException{
conn=DriverManager.getConnection("jdbc:mysql//localhost/test","","");
stm=conn.createStatement();
rs=stm.executeQuery(query);
}
}
请指点!
无法将 java.lang.String 转换为 java.sql.ResultSet.我以前也遇到过这种情况,但一直没解决,
请问这句话是有什麽引起的呢?到底是哪个语句写错了会出现这个提示?我的insert.jsp和javabean如下所示:
/////////////insert.jsp///////////////////////////////
////////////////////////lyobean.java/////////////////////////////////////
package liren;
import java.sql.*;
public class lyobean{
ResultSet rs;
Statement stm;
Connection conn;
String name,email,title,content;
String sql="select * from li";
String query="insert into li values('"+name+"','"+email+"','"+title+"','"+content+"')";
public lyobean()throws SQLException{
try{
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
}catch(Exception e){
System.out.println("Can't conect the driver!");
}
}
public ResultSet executeQuery(ResultSet rs)throws SQLException{
rs=null;
conn=DriverManager.getConnection("jdbc:mysql//localhost/test","user=lyo","qijiashe");///我设置的mysql的密码///
stm=conn.createStatement();
rs=stm.executeQuery(sql);
return rs;
}
public void executeUpdate(String query)throws SQLException{
conn=DriverManager.getConnection("jdbc:mysql//localhost/test","","");
stm=conn.createStatement();
rs=stm.executeQuery(query);
}
}
请指点!
|
public ResultSet executeQuery(ResultSet rs)throws SQLException{
参数应该是String 类型的
参数应该是String 类型的
|
我帮你改了一下,不知可否
package liren;
import java.sql.*;
public class lyobean{
ResultSet rs;
Statement stm;
Connection conn;
public lyobean()throws SQLException{
try{
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
}catch(Exception e){
System.out.println("Can't conect the driver!");
}
}
public ResultSet executeQuery(String sql)throws SQLException{
rs=null;
conn=DriverManager.getConnection("jdbc:mysql//localhost/test","user=lyo","qijiashe");///我设置的mysql的密码///
stm=conn.createStatement();
rs=stm.executeQuery(sql);
return rs;
}
public void executeUpdate(String query)throws SQLException{
conn=DriverManager.getConnection("jdbc:mysql//localhost/test","","");
stm=conn.createStatement();
rs=stm.executeQuery(query);
}
}
package liren;
import java.sql.*;
public class lyobean{
ResultSet rs;
Statement stm;
Connection conn;
public lyobean()throws SQLException{
try{
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
}catch(Exception e){
System.out.println("Can't conect the driver!");
}
}
public ResultSet executeQuery(String sql)throws SQLException{
rs=null;
conn=DriverManager.getConnection("jdbc:mysql//localhost/test","user=lyo","qijiashe");///我设置的mysql的密码///
stm=conn.createStatement();
rs=stm.executeQuery(sql);
return rs;
}
public void executeUpdate(String query)throws SQLException{
conn=DriverManager.getConnection("jdbc:mysql//localhost/test","","");
stm=conn.createStatement();
rs=stm.executeQuery(query);
}
}