当我尝试执行以下代码时,我收到此错误com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'NIRAV' in 'where Clause' 。
package all_forms;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import javax.swing.JOptionPane;
public class Select_operation {
private Connection con=null;
private PreparedStatement pstmt=null;
private ResultSet rs=null;
String query;
public Select_operation(Connection conn)
{
con=conn;
}
public ResultSet select(String search)
{
query="select * from student where id="+search+" or name like'"+search+"%'";
try
{
pstmt=con.prepareStatement(query);
rs=pstmt.executeQuery();
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null, ""+e, "Error",JOptionPane.ERROR_MESSAGE);
}
return rs;
}
}