Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Main {
- public static void main(String[] args) throws Exception {
- HashSet<String> uniqueWords = new HashSet<>();
- try (PDDocument document = PDDocument.load(new File("D:/PDF/my.pdf"))) {
- if (!document.isEncrypted()) {
- PDFTextStripper tStripper = new PDFTextStripper();
- String pdfFileInText = tStripper.getText(document);
- String lines[] = pdfFileInText.split("\r?\n");
- for (String line : lines) {
- String[] words = line.split(" ");
- for (String word : words) {
- uniqueWords.add(word);
- }
- }
- System.out.println(uniqueWords);
- }
- } catch (IOException e){
- System.err.println("Exception while trying to read pdf document - " + e);
- }
- MysqlAccess connection=new MysqlAccess();
- connection.readDataBase();
- }
- }
- public class MysqlAccess {
- private Connection connect = null;
- private Statement statement = null;
- private PreparedStatement preparedStatement = null;
- private ResultSet resultSet = null;
- public void readDataBase() throws Exception {
- try {
- // This will load the MySQL driver, each DB has its own driver
- Class.forName("com.mysql.jdbc.Driver");
- // Setup the connection with the DB
- connect = DriverManager
- .getConnection("jdbc:mysql://126.32.3.20/fulltext_ltat?"
- + "user=root&password=root");
- // Statements allow to issue SQL queries to the database
- statement = connect.createStatement();
- System.out.print("Connected");
- // Result set get the result of the SQL query
- preparedStatement = connect
- .prepareStatement("insert into fulltext_ltat.index_detail values (default, ?, ?)");
- preparedStatement.setString(1, "D:\Full Text Indexing\testIndex");
- preparedStatement.setString(2, "test");
- preparedStatement.executeUpdate();
- resultSet = statement
- .executeQuery("select * from fulltext_ltat.index_detail");
- writeResultSet(resultSet);
- } catch (Exception e) {
- throw e;
- } finally {
- close();
- }
- }
- private void writeResultSet(ResultSet resultSet) throws SQLException {
- // ResultSet is initially before the first data set
- while (resultSet.next()) {
- // It is possible to get the columns via name
- // also possible to get the columns via the column number
- // which starts at 1
- // e.g. resultSet.getSTring(2);
- String path = resultSet.getString("path");
- String word = resultSet.getString("word");
- System.out.println();
- System.out.println("path: " + path);
- System.out.println("word: " + word);
- }
- }
- private void close() {
- try {
- if (resultSet != null) {
- resultSet.close();
- }
- if (statement != null) {
- statement.close();
- }
- if (connect != null) {
- connect.close();
- }
- } catch (Exception e) {
- }
- }
- }
Add Comment
Please, Sign In to add comment