How to Search contents of a table?
SolutionFollowing method uses where & like sql Commands to search through the database.
import java.sql.*; public class jdbcConn { public static void main(String[] args) throws Exception { Class.forName("org.apache.derby.jdbc.ClientDriver"); Connection con = DriverManager.getConnection( "jdbc:derby://localhost:1527/testDb","username", "password"); Statement stmt = con.createStatement(); String query[] = { "SELECT * FROM emp where id = 1", "select name from emp where name like 'ravi_'", "select name from emp where name like 'ravi%'" }; for(String q : query) { ResultSet rs = stmt.executeQuery(q); System.out.println("Names for query "+q+" are"); while (rs.next()) { String name = rs.getString("name"); System.out.print(name+" "); } System.out.println(); } } }Result
The above code sample will produce the following result.The result may vary.
Names for query SELECT * FROM emp where id=1 are ravi Names for query select name from emp where name like 'ravi_' are ravi2 ravi3 Names for query select name from emp where name like 'ravi%' are ravi ravi2 ravi3 ravi123 ravi222
java_jdbc.htm
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4