Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public String[] findRes(String nameRes) {
- try {
- Class.forName("com.mysql.jdbc.Driver");
- String name = "it_56070014";
- String password = "4a3DskLl2b";
- String url = "jdbc:mysql://database.it.kmitl.ac.th:3306/it_56070014?zeroDateTimeBehavior=convertToNull";
- Connection conn;
- conn = DriverManager.getConnection(url, name, password);
- if (nameRes.equals("")) {
- String res[] = new String[1000];
- int i = 0;
- Statement stmt = conn.createStatement();
- String sql = "SELECT research_name from researchs";
- ResultSet rs = stmt.executeQuery(sql);
- while (rs.next()) {
- res[i] = rs.getString("research_name");
- i++;
- }
- return res;
- } else {
- String words;
- Statement stmt = conn.createStatement();
- String sql = "SELECT research_name from researchs where research_name like '%" +nameRes+ "%'" ;
- ResultSet rs = stmt.executeQuery(sql);
- int count = 0;
- String wordsAll[] = new String[100];
- while (rs.next()) {
- wordsAll[count] = rs.getString("research_name");
- count++;
- }
- return wordsAll;
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- return new String[0];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement