Guest User

Untitled

a guest
Oct 9th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.33 KB | None | 0 0
  1. public class Main {
  2.  
  3. public static void main(String[] args) throws Exception {
  4.  
  5. HashSet<String> uniqueWords = new HashSet<>();
  6. try (PDDocument document = PDDocument.load(new File("D:/PDF/my.pdf"))) {
  7.  
  8. if (!document.isEncrypted()) {
  9.  
  10. PDFTextStripper tStripper = new PDFTextStripper();
  11. String pdfFileInText = tStripper.getText(document);
  12. String lines[] = pdfFileInText.split("\r?\n");
  13. for (String line : lines) {
  14. String[] words = line.split(" ");
  15.  
  16. for (String word : words) {
  17. uniqueWords.add(word);
  18.  
  19. }
  20.  
  21. }
  22. System.out.println(uniqueWords);
  23.  
  24. }
  25. } catch (IOException e){
  26. System.err.println("Exception while trying to read pdf document - " + e);
  27. }
  28.  
  29. MysqlAccess connection=new MysqlAccess();
  30. connection.readDataBase();
  31.  
  32. }
  33.  
  34. }
  35.  
  36. public class MysqlAccess {
  37. private Connection connect = null;
  38. private Statement statement = null;
  39. private PreparedStatement preparedStatement = null;
  40. private ResultSet resultSet = null;
  41.  
  42. public void readDataBase() throws Exception {
  43. try {
  44. // This will load the MySQL driver, each DB has its own driver
  45. Class.forName("com.mysql.jdbc.Driver");
  46. // Setup the connection with the DB
  47. connect = DriverManager
  48. .getConnection("jdbc:mysql://126.32.3.20/fulltext_ltat?"
  49. + "user=root&password=root");
  50.  
  51. // Statements allow to issue SQL queries to the database
  52. statement = connect.createStatement();
  53. System.out.print("Connected");
  54. // Result set get the result of the SQL query
  55.  
  56. preparedStatement = connect
  57. .prepareStatement("insert into fulltext_ltat.index_detail values (default, ?, ?)");
  58.  
  59. preparedStatement.setString(1, "D:\Full Text Indexing\testIndex");
  60. preparedStatement.setString(2, "test");
  61. preparedStatement.executeUpdate();
  62. resultSet = statement
  63. .executeQuery("select * from fulltext_ltat.index_detail");
  64.  
  65.  
  66.  
  67. writeResultSet(resultSet);
  68. } catch (Exception e) {
  69. throw e;
  70. } finally {
  71. close();
  72. }
  73.  
  74. }
  75.  
  76.  
  77.  
  78. private void writeResultSet(ResultSet resultSet) throws SQLException {
  79. // ResultSet is initially before the first data set
  80. while (resultSet.next()) {
  81. // It is possible to get the columns via name
  82. // also possible to get the columns via the column number
  83. // which starts at 1
  84. // e.g. resultSet.getSTring(2);
  85. String path = resultSet.getString("path");
  86. String word = resultSet.getString("word");
  87.  
  88.  
  89.  
  90. System.out.println();
  91. System.out.println("path: " + path);
  92. System.out.println("word: " + word);
  93.  
  94. }
  95. }
  96.  
  97.  
  98. private void close() {
  99. try {
  100. if (resultSet != null) {
  101. resultSet.close();
  102. }
  103.  
  104. if (statement != null) {
  105. statement.close();
  106. }
  107.  
  108. if (connect != null) {
  109. connect.close();
  110. }
  111. } catch (Exception e) {
  112.  
  113. }
  114. }
  115.  
  116. }
Add Comment
Please, Sign In to add comment