Java JDBC MySQL Connection getIonMassList()

Here you can find the source of getIonMassList()

Description

get Ion Mass List

License

Open Source License

Declaration

public static List<String[]> getIonMassList() throws IOException 

Method Source Code

//package com.java2s;
/*******************************************************************************
 *
 * Copyright (C) 2011 MassBank Project/* w  ww.  j  ava 2s .co  m*/
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 *
 *******************************************************************************
 *
 * ???w???????????[?e?B???e?B?N???X
 *
 * ver 1.0.1 2012.11.01
 *
 ******************************************************************************/

import java.util.List;
import java.util.ArrayList;

import java.io.IOException;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class Main {

    public static List<String[]> getIonMassList() throws IOException {
        List<String[]> massList = new ArrayList();
        try {

            Class.forName("com.mysql.jdbc.Driver");
            String conUrl = "jdbc:mysql://localhost/FORMULA_STRUCTURE_RELATION";
            Connection con = DriverManager.getConnection(conUrl, "bird",
                    "bird2006");
            Statement stmt = con.createStatement();
            String sql = "SELECT FORMULA, MASS FROM ION_MASS order by MASS";
            ResultSet rs = stmt.executeQuery(sql);
            while (rs.next()) {
                String formula = rs.getString("FORMULA");
                String mass = rs.getString("MASS");
                massList.add(new String[] { formula, mass });
            }
            rs.close();
            stmt.close();
            con.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return massList;
    }
}

Related

  1. getDBConnection(String database)
  2. getDBConnection(String dbServer, String dbName, String dbUser, String dbPass)
  3. getDBConnection(String urlFormat, String host, Integer port, String database, String user, String password)
  4. getDMPConn()
  5. getGoogleCloudDBConnection()
  6. getJdbcConnection(String host, int port, String name, String user, String password)
  7. getJtdsConnection()
  8. getMaxID()
  9. getMysqlCon(String ip, String port, String dbname, String username, String password)