Java JDBC Sqlite Connection getUniqLabels()

Here you can find the source of getUniqLabels()

Description

get Uniq Labels

License

Apache License

Declaration

public static List<String> getUniqLabels() 

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.ArrayList;

import java.util.List;

public class Main {
    public static List<String> getUniqLabels() {
        Connection c = null;/*from ww  w  .  j a v  a 2s  .  c o  m*/
        Statement stmt = null;
        List<String> outputs = new ArrayList<String>();
        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 distinct(LABEL)  from DOC_LABEL order by LABEL;");
            String label;
            while (rs.next()) {
                label = rs.getString("LABEL");
                outputs.add(label);
            }
            rs.close();
            stmt.close();
            c.close();
        } catch (Exception e) {
            System.err.println(e.getClass().getName() + ": " + e.getMessage());
            System.exit(0);
        }
        return outputs;
    }
}

Related

  1. getConnection(String dbFilePath)
  2. getConnection(String dbName)
  3. getNewConnection(File dbFile)
  4. getSenatorProp(String topicId)
  5. getSQLiteConnection()
  6. modify(String sql)
  7. query(String sql)
  8. removeLabel()
  9. runSetupScript(final String setupScriptPath)