Java JDBC Sqlite Connection getSenatorProp(String topicId)

Here you can find the source of getSenatorProp(String topicId)

Description

get Senator Prop

License

Apache License

Declaration

private static TreeMap<String, Double> getSenatorProp(String topicId) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.sql.Connection;
import java.sql.DriverManager;

import java.sql.ResultSet;

import java.sql.Statement;

import java.util.HashMap;

import java.util.TreeMap;

public class Main {
    private static final HashMap<String, String> docId_actorId = new HashMap<String, String>();

    private static TreeMap<String, Double> getSenatorProp(String topicId) {
        Connection c = null;//from   w  w  w.  j  a  v a2 s  .  c  om
        Statement stmt = null;
        TreeMap<String, Double> output = new TreeMap<String, Double>();
        try {
            Class.forName("org.sqlite.JDBC");
            c = DriverManager.getConnection("jdbc:sqlite:dbs/newpress.db");
            c.setAutoCommit(false);
            System.out.println("Opened database successfully");

            stmt = c.createStatement();
            ResultSet rs = stmt
                    .executeQuery("SELECT DOCID, TOPICPROP from DOC_TOPIC where TOPICID = '" + topicId + "';");

            String docId = "";
            String topicProp = "";
            String actorId = "";
            while (rs.next()) {
                docId = rs.getString("DOCID");
                topicProp = rs.getString("TOPICPROP");
                actorId = docId_actorId.get(docId);
                if (output.containsKey(actorId)) {
                    output.put(actorId, output.get(actorId) + Double.parseDouble(topicProp));
                } else {

                    output.put(actorId, Double.parseDouble(topicProp));
                }
            }
            rs.close();
            stmt.close();
            c.close();
        } catch (Exception e) {
            System.err.println(e.getClass().getName() + ": " + e.getMessage());
            System.exit(0);
        }
        return output;
    }
}

Related

  1. getConnection(final String databaseName)
  2. getConnection(String dbFile)
  3. getConnection(String dbFilePath)
  4. getConnection(String dbName)
  5. getNewConnection(File dbFile)
  6. getSQLiteConnection()
  7. getUniqLabels()
  8. modify(String sql)
  9. query(String sql)