Hello Ragini
This is code, as per your requirement u made modification
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
public class Test1 {
public void search(){
String searchstring = "raj";
String srch = "select name from Mytable where name LIKE '%" + searchstring + "%'";
System.out.println(srch);
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:
mysql://localhost:3306/testing";, "root", "");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(srch);
if(!rs.next()){
System.out.println("No Record Found" + rs.getRow());
}else{
rs = stmt.executeQuery(srch);
while(rs.next()){
System.out.println(rs.getString("name"));
}
}
}catch(Exception ex){
System.out.println("Exception");
}
}
public static void main(String s[]){
Test1 t = new Test1();
t.search();
}
}
Regards
Rajaniaknt Mishra
[email protected]