Java SQL Type getSemestre(Integer actionformation_id, Connection connection, String actionformation_libellecourt)

Here you can find the source of getSemestre(Integer actionformation_id, Connection connection, String actionformation_libellecourt)

Description

get Semestre

License

Open Source License

Declaration

public static String getSemestre(Integer actionformation_id,
        Connection connection, String actionformation_libellecourt) 

Method Source Code

//package com.java2s;
/****************************************************************************

 ASCMII is a web application developped for the Ecole Centrale de Nantes
 aiming to organize quizzes during courses or lectures.
 Copyright (C) 2013  Malik Olivier Boussejra

 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 3 of the License, or
 (at your option) any later version./*  w w w .  j av  a 2s  .  c  om*/

 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, see http://www.gnu.org/licenses/.

 ******************************************************************************/

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

public class Main {

    public static String getSemestre(Integer actionformation_id,
            Connection connection, String actionformation_libellecourt) {
        String semestre = "";
        String theQuery = "SELECT structures_id,typestructure_id "
                + "FROM actionstructure " + "NATURAL JOIN structures "
                + "WHERE actionformation_id=" + actionformation_id;
        try {
            System.out.println("Executing : " + theQuery);
            Statement theStmt = connection.createStatement();
            ResultSet theRS1 = theStmt.executeQuery(theQuery);
            while (theRS1.next()) {
                Integer typestructure_id = theRS1
                        .getInt("typestructure_id");
                Integer structure_id = theRS1.getInt("structures_id");
                int i = 0;
                while (typestructure_id != 16 && typestructure_id != 1
                        && typestructure_id != 10) {
                    theQuery = "SELECT structures_id,typestructure_id "
                            + "FROM structuresliens "
                            + "INNER JOIN structures ON(structures.structures_id=structuresliens.structures_pere_id) "
                            + "WHERE structures_fils_id=" + structure_id;
                    theStmt = connection.createStatement();
                    ResultSet theRS = theStmt.executeQuery(theQuery);
                    while (theRS.next()) {
                        System.out.println("NEXT:" + structure_id + " "
                                + typestructure_id + " : " + i);
                        typestructure_id = theRS.getInt("typestructure_id");
                        structure_id = theRS.getInt("structures_id");
                    }
                    i++;
                    System.out.println(structure_id + " "
                            + typestructure_id + " : " + i);
                }
                theQuery = "SELECT structures_libelle,structures_libellecourt "
                        + "FROM structures "
                        + "WHERE structures_id="
                        + structure_id;
                theStmt = connection.createStatement();
                ResultSet theRS = theStmt.executeQuery(theQuery);
                while (theRS.next()) {
                    String sem = theRS.getString("structures_libelle");
                    semestre = toLibelleSemestreCourt(sem,
                            actionformation_libellecourt);
                    System.out.println(semestre);
                }
            }
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return semestre;
    }

    private static String toLibelleSemestreCourt(String sem, String libelle) {
        if (sem.startsWith("Semestre ")) {
            if (libelle.endsWith("_S5")) {
                return "";
            } else if (libelle.endsWith("_S6")) {
                return "";
            } else if (libelle.endsWith("_S7")) {
                return "";
            } else if (libelle.endsWith("_S8")) {
                return "";
            } else {
                return "S" + sem.substring(9);
            }
        } else {
            return "";
        }
    }
}

Related

  1. getPartitionSizeValidationError(int colType, String column, String partitionSize)
  2. getPreferredHibernateType(int sqlType, int size, int precision, int scale, boolean nullable, boolean generatedIdentifier)
  3. getPreparedStatementSetMethodMap()
  4. getPrimitiveInstance(Type type, String valueString)
  5. getReturnClass(String typeName)
  6. getSerialPrimaryKeyTypeString(Connection conn)
  7. getSimpleTypeString(String dbType)
  8. getSQLAttributeType(int sqlType)
  9. getSQLException(String message, String sqlState, Exception exception)