Guest User

Untitled

a guest
Jan 18th, 2019
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.39 KB | None | 0 0
  1. import java.util.*;
  2. import java.sql.*;
  3. import java.io.*;
  4.  
  5. public class TokensOfString
  6. {
  7. public static void main(String[] args)
  8. {
  9. String str;
  10. String query = "";
  11. try
  12. {
  13. int i =0, cntToken =0;
  14. BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  15. System.out.println("Enter the keywords to be searched");
  16. str = br.readLine();
  17. StringTokenizer words = new StringTokenizer(str, ",");
  18. cntToken = words.countTokens();
  19. //System.out.println("No. of Tokens = "+cntToken);
  20.  
  21. String token[]= new String[cntToken];
  22.  
  23. while(words.hasMoreElements())
  24. {
  25. token[i] = words.nextToken().trim();
  26. //System.out.println(token[i]);
  27. i++;
  28. }
  29. //System.out.println(++i+" : "+words.nextElement().toString().trim());
  30.  
  31. query = "SELECT * from can_skills where skills like '"+ token[0] +"%'";
  32. // System.out.println("Query at 34 : "+query);
  33. if(cntToken == 1)
  34. {
  35. query ="";
  36. query = "SELECT * from can_skills where skills like '"+ str +"%'";
  37. }
  38. if(cntToken > 1)
  39. {
  40. for( int j=1; j < cntToken; j++)
  41. query = query + " or skills like '"+ token[j] +"%'";
  42. }
  43. System.out.println("Query at 43 : "+query);
  44.  
  45. Connection con = null;
  46. Class.forName("com.mysql.jdbc.Driver");
  47. String hostName = "localhost";
  48. String port = "3306";
  49. String userName = "root";
  50. String password = "root";
  51. con = DriverManager.getConnection("jdbc:mysql://" + hostName + ":" + port + "/prem", userName, password);
  52. Statement statement= con.createStatement();
  53. ResultSet rs = statement.executeQuery(query);
  54. while(rs.next())
  55. {
  56. System.out.println(rs.getString(4));
  57. }
  58.  
  59. }
  60. catch(ClassNotFoundException e){ System.out.println(e); }
  61. catch(Exception ex){ System.out.println(ex); }
  62. }
  63. }
  64.  
  65. select *
  66. from Candidate
  67. where skills regexp '^C,| C,| C$'
  68.  
  69. "SELECT * from can_skills where skills regexp '^" + token[0] + ",| " + token[0] + ",| " + token[0] + "$'";
  70.  
  71. "select * from can_skills where skills REGEXP '" . token . ",?'"
Add Comment
Please, Sign In to add comment