Example usage for java.sql Time valueOf

List of usage examples for java.sql Time valueOf

Introduction

In this page you can find the example usage for java.sql Time valueOf.

Prototype

@SuppressWarnings("deprecation")
public static Time valueOf(LocalTime time) 

Source Link

Document

Obtains an instance of Time from a LocalTime object with the same hour, minute and second time value as the given LocalTime .

Usage

From source file:edu.ku.brc.specify.toycode.mexconabio.FileMakerToMySQL.java

/**
 * //from   w  ww . jav  a 2 s.  co m
 */
private void writeRow() {
    try {
        int i = 0;
        int col = 1;
        for (FieldDef fd : fields) {
            if (fd.getMaxSize() > 0) {
                String val = values.get(i);
                if (StringUtils.isNotEmpty(val)) {
                    switch (fd.getType()) {
                    case eText:
                        pStmt.setString(col, val);
                        break;

                    case eNumber: {
                        if (StringUtils.isNumericSpace(val)) {
                            if (fd.isDouble()) {
                                pStmt.setDouble(col, Double.parseDouble(val));
                            } else {
                                pStmt.setInt(col, Integer.parseInt(val));
                            }
                        } else {
                            pStmt.setObject(col, null);
                        }
                        break;
                    }

                    case eDate: {
                        Date date = null;
                        try {
                            date = sdf.parse(val);
                            pStmt.setDate(col, new java.sql.Date(date.getTime()));

                        } catch (Exception ex) {
                            pStmt.setObject(col, null);
                        }

                        break;
                    }

                    case eTime: {
                        Time time = null;
                        try {
                            time = Time.valueOf(val);
                        } catch (Exception ex) {
                        }
                        pStmt.setTime(col, time);
                        break;
                    }
                    }
                } else {
                    pStmt.setObject(col, null);
                }
                col++;
            }
            i++;
        }
    } catch (SQLException ex) {
        ex.printStackTrace();
    }

    try {
        pStmt.execute();

    } catch (SQLException ex) {
        ex.printStackTrace();
    }
    values.clear();
}

From source file:com.kylinolap.rest.service.QueryService.java

/**
 * @param preparedState/*  ww w. j  a  v  a 2s  . c  om*/
 * @param param
 * @throws SQLException
 */
private void setParam(PreparedStatement preparedState, int index, StateParam param) throws SQLException {
    boolean isNull = (null == param.getValue());

    Class<?> clazz = Object.class;
    try {
        clazz = Class.forName(param.getClassName());
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }

    Rep rep = Rep.of(clazz);

    switch (rep) {
    case PRIMITIVE_CHAR:
    case CHARACTER:
    case STRING:
        preparedState.setString(index, isNull ? null : String.valueOf(param.getValue()));
        break;
    case PRIMITIVE_INT:
    case INTEGER:
        preparedState.setInt(index, isNull ? null : Integer.valueOf(param.getValue()));
        break;
    case PRIMITIVE_SHORT:
    case SHORT:
        preparedState.setShort(index, isNull ? null : Short.valueOf(param.getValue()));
        break;
    case PRIMITIVE_LONG:
    case LONG:
        preparedState.setLong(index, isNull ? null : Long.valueOf(param.getValue()));
        break;
    case PRIMITIVE_FLOAT:
    case FLOAT:
        preparedState.setFloat(index, isNull ? null : Float.valueOf(param.getValue()));
        break;
    case PRIMITIVE_DOUBLE:
    case DOUBLE:
        preparedState.setDouble(index, isNull ? null : Double.valueOf(param.getValue()));
        break;
    case PRIMITIVE_BOOLEAN:
    case BOOLEAN:
        preparedState.setBoolean(index, isNull ? null : Boolean.parseBoolean(param.getValue()));
        break;
    case PRIMITIVE_BYTE:
    case BYTE:
        preparedState.setByte(index, isNull ? null : Byte.valueOf(param.getValue()));
        break;
    case JAVA_UTIL_DATE:
    case JAVA_SQL_DATE:
        preparedState.setDate(index, isNull ? null : java.sql.Date.valueOf(param.getValue()));
        break;
    case JAVA_SQL_TIME:
        preparedState.setTime(index, isNull ? null : Time.valueOf(param.getValue()));
        break;
    case JAVA_SQL_TIMESTAMP:
        preparedState.setTimestamp(index, isNull ? null : Timestamp.valueOf(param.getValue()));
        break;
    default:
        preparedState.setObject(index, isNull ? null : param.getValue());
    }
}

From source file:adalid.core.programmers.AbstractJavaProgrammer.java

protected String getString(Object object, Class<?> type) {
    if (object == null || type == null) {
        return null;
    }/*from w w  w. j  a va  2  s . com*/
    String errmsg = "cannot get \"" + javaLangLess(type) + "\" from \"" + object + "\"";
    String string = getString(object);
    try {
        if (string == null) {
            return null;
        } else if (Boolean.class.isAssignableFrom(type)) {
            return "" + Boolean.valueOf(string);
        } else if (Character.class.isAssignableFrom(type)) {
            return getCharacterString(string);
        } else if (String.class.isAssignableFrom(type)) {
            return string;
        } else if (Byte.class.isAssignableFrom(type)) {
            return "" + Byte.valueOf(string);
        } else if (Short.class.isAssignableFrom(type)) {
            return "" + Short.valueOf(string);
        } else if (Integer.class.isAssignableFrom(type)) {
            return "" + Integer.valueOf(string);
        } else if (Long.class.isAssignableFrom(type)) {
            return "" + Long.valueOf(string);
        } else if (Float.class.isAssignableFrom(type)) {
            return "" + Float.valueOf(string);
        } else if (Double.class.isAssignableFrom(type)) {
            return "" + Double.valueOf(string);
        } else if (BigInteger.class.isAssignableFrom(type)) {
            return "" + new BigInteger(string);
        } else if (BigDecimal.class.isAssignableFrom(type)) {
            return "" + new BigDecimal(string);
        } else if (object instanceof java.util.Date && Date.class.isAssignableFrom(type)) {
            string = TimeUtils.jdbcDateString(object);
            return getString(Date.valueOf(string));
        } else if (object instanceof java.util.Date && Time.class.isAssignableFrom(type)) {
            string = TimeUtils.jdbcTimeString(object);
            return getString(Time.valueOf(string));
        } else if (object instanceof java.util.Date && Timestamp.class.isAssignableFrom(type)) {
            string = TimeUtils.jdbcTimestampString(object);
            return getString(Timestamp.valueOf(string));
        } else {
            return null;
        }
    } catch (IllegalArgumentException ex) {
        //          logger.error(errmsg, ThrowableUtils.getCause(ex));
        logger.error(errmsg);
        return null;
    }
}

From source file:edu.ncsa.sstde.indexing.postgis.PostgisIndexer.java

private Object parseLiteral(Literal literal) {
    String uri = literal.getDatatype().stringValue();
    if (DataTypeURI.isGeometry(uri)) {
        return IndexedStatement.asGeometry(literal, true);
    } else if (DataTypeURI.DATETIME.equals(uri)) {
        try {/*from www  .  j a va2s. c  o  m*/
            return new Timestamp(DateFormatter.getInstance().parse(literal.getLabel()).getTime());
        } catch (java.text.ParseException e) {
            e.printStackTrace();
        }
    } else if (DataTypeURI.isText(uri)) {
        return literal.getLabel();
    } else if (DataTypeURI.DOUBLE.equals(uri)) {
        return Double.valueOf(literal.getLabel());
    } else if (DataTypeURI.FLOAT.equals(uri)) {
        return Float.valueOf(literal.getLabel());
    } else if (DataTypeURI.INTEGER.equals(uri)) {
        return Integer.valueOf(literal.getLabel());
    } else if (DataTypeURI.TIME.equals(uri)) {
        return Time.valueOf(literal.getLabel());
    }

    return null;
}

From source file:com.alibaba.wasp.jdbc.TestPreparedStatement.java

public void testObject() throws SQLException {
    Statement stat = conn.createStatement();
    ResultSet rs;/*  www .java  2  s.c o m*/
    stat.execute("CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR(255))");
    stat.execute("INSERT INTO TEST VALUES(1, 'Hello')");
    PreparedStatement prep = conn
            .prepareStatement("SELECT ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? FROM TEST");
    prep.setObject(1, Boolean.TRUE);
    prep.setObject(2, "Abc");
    prep.setObject(3, new BigDecimal("10.2"));
    prep.setObject(4, new Byte((byte) 0xff));
    prep.setObject(5, new Short(Short.MAX_VALUE));
    prep.setObject(6, new Integer(Integer.MIN_VALUE));
    prep.setObject(7, new Long(Long.MAX_VALUE));
    prep.setObject(8, new Float(Float.MAX_VALUE));
    prep.setObject(9, new Double(Double.MAX_VALUE));
    prep.setObject(10, Date.valueOf("2001-02-03"));
    prep.setObject(11, Time.valueOf("04:05:06"));
    prep.setObject(12, Timestamp.valueOf("2001-02-03 04:05:06.123456789"));
    prep.setObject(13, new java.util.Date(Date.valueOf("2001-02-03").getTime()));
    prep.setObject(14, new byte[] { 10, 20, 30 });
    prep.setObject(15, new Character('a'), Types.OTHER);
    prep.setObject(16, "2001-01-02", Types.DATE);
    // converting to null seems strange...
    prep.setObject(17, "2001-01-02", Types.NULL);
    prep.setObject(18, "3.725", Types.DOUBLE);
    prep.setObject(19, "23:22:21", Types.TIME);
    prep.setObject(20, new java.math.BigInteger("12345"), Types.OTHER);
    rs = prep.executeQuery();
    rs.next();
    assertTrue(rs.getObject(1).equals(Boolean.TRUE));
    assertTrue(rs.getObject(2).equals("Abc"));
    assertTrue(rs.getObject(3).equals(new BigDecimal("10.2")));
    assertTrue(rs.getObject(4).equals((byte) 0xff));
    assertTrue(rs.getObject(5).equals(new Short(Short.MAX_VALUE)));
    assertTrue(rs.getObject(6).equals(new Integer(Integer.MIN_VALUE)));
    assertTrue(rs.getObject(7).equals(new Long(Long.MAX_VALUE)));
    assertTrue(rs.getObject(8).equals(new Float(Float.MAX_VALUE)));
    assertTrue(rs.getObject(9).equals(new Double(Double.MAX_VALUE)));
    assertTrue(rs.getObject(10).equals(Date.valueOf("2001-02-03")));
    assertEquals("04:05:06", rs.getObject(11).toString());
    assertTrue(rs.getObject(11).equals(Time.valueOf("04:05:06")));
    assertTrue(rs.getObject(12).equals(Timestamp.valueOf("2001-02-03 04:05:06.123456789")));
    assertTrue(rs.getObject(13).equals(Timestamp.valueOf("2001-02-03 00:00:00")));
    assertEquals(new byte[] { 10, 20, 30 }, (byte[]) rs.getObject(14));
    assertTrue(rs.getObject(15).equals('a'));
    assertTrue(rs.getObject(16).equals(Date.valueOf("2001-01-02")));
    assertTrue(rs.getObject(17) == null && rs.wasNull());
    assertTrue(rs.getObject(18).equals(new Double(3.725)));
    assertTrue(rs.getObject(19).equals(Time.valueOf("23:22:21")));
    assertTrue(rs.getObject(20).equals(new java.math.BigInteger("12345")));

    // } else if(x instanceof java.io.Reader) {
    // return session.createLob(Value.CLOB,
    // TypeConverter.getInputStream((java.io.Reader)x), 0);
    // } else if(x instanceof java.io.InputStream) {
    // return session.createLob(Value.BLOB, (java.io.InputStream)x, 0);
    // } else {
    // return ValueBytes.get(TypeConverter.serialize(x));

    stat.execute("DROP TABLE TEST");

}

From source file:edu.ku.brc.specify.toycode.mexconabio.MexConvToSQL.java

/**
 * /*from   w  ww . j a va 2 s .  c  om*/
 */
public void convert(final String databaseName, final String tableName, final String srcFileName,
        final String xmlFileName) {
    String[] months = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", };
    HashMap<String, Integer> monthHash = new HashMap<String, Integer>();
    for (String mn : months) {
        monthHash.put(mn, monthHash.size() + 1);
    }

    Connection conn = null;
    Statement stmt = null;
    try {
        conn = DriverManager.getConnection(
                "jdbc:mysql://localhost/" + databaseName + "?characterEncoding=UTF-8&autoReconnect=true",
                "root", "root");
        stmt = conn.createStatement();

        FMPCreateTable fmpInfo = new FMPCreateTable(tableName, null, true);
        fmpInfo.process(xmlFileName);

        boolean doCreateTable = true;
        if (doCreateTable) {
            processFieldSizes(fmpInfo, srcFileName);

            PrintWriter pw = new PrintWriter(new File("fields.txt"));
            int i = 0;
            for (FieldDef fd : fmpInfo.getFields()) {
                pw.println(i + " " + fd.getName() + "\t" + fd.getType() + "\t" + fd.isDouble());
                i++;
            }
            pw.close();

            BasicSQLUtils.update(conn, fmpInfo.dropTableStr());

            String sqlCreateTable = fmpInfo.createTableStr();

            BasicSQLUtils.update(conn, sqlCreateTable);

            System.out.println(sqlCreateTable);
        }

        String prepSQL = fmpInfo.getPrepareStmtStr(true, true);
        System.out.println(prepSQL);
        pStmt = conn.prepareStatement(prepSQL);

        Vector<FieldDef> fieldDefs = fmpInfo.getFields();

        int rowCnt = 0;
        BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(srcFileName)));
        String str = in.readLine();
        str = in.readLine();
        while (str != null) {
            String line = str;
            char sep = '`';
            String sepStr = "";
            for (char c : seps) {
                if (line.indexOf(c) == -1) {
                    sepStr += c;
                    sep = c;
                    break;
                }
            }
            str = StringUtils.replace(str.substring(1, str.length() - 1), "\",\"", sepStr);
            Vector<String> fields = split(str, sep);

            SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");

            int col = 1;
            int inx = 0;
            for (String fld : fields) {
                String value = fld.trim();
                FieldDef fd = fieldDefs.get(inx);

                switch (fd.getType()) {
                case eText:
                case eMemo: {
                    if (value.length() > 0) {
                        //value = FMPCreateTable.convertFromUTF8(value);
                        if (value.length() <= fd.getMaxSize()) {
                            pStmt.setString(col, value);
                        } else {
                            System.err.println(String.format("The data for `%s` max(%d) is too big %d",
                                    fd.getName(), fd.getMaxSize(), value.length()));
                            pStmt.setString(col, null);
                        }
                    } else {
                        pStmt.setString(col, null);
                    }
                }
                    break;

                case eNumber: {
                    if (StringUtils.isNotEmpty(value)) {
                        String origValue = value;
                        String val = value.charAt(0) == '' ? value.substring(1) : value;
                        val = val.charAt(0) == '-' ? val.substring(1) : val;
                        val = val.indexOf('.') > -1 ? StringUtils.replace(val, ".", "") : val;
                        val = val.indexOf('') > -1 ? StringUtils.replace(val, "", "") : val;

                        if (StringUtils.isNumericSpace(val)) {
                            if (fd.isDouble()) {
                                pStmt.setDouble(col, Double.parseDouble(val));
                            } else {
                                pStmt.setInt(col, Integer.parseInt(val));
                            }
                        } else if (val.startsWith("ca. ")) {
                            pStmt.setInt(col, Integer.parseInt(val.substring(4)));
                        } else if (val.startsWith("ca ")) {
                            pStmt.setInt(col, Integer.parseInt(val.substring(3)));
                        } else {
                            System.err.println(col + " Bad Number val[" + val + "] origValue[" + origValue
                                    + "] " + fieldDefs.get(col - 1).getName());
                            pStmt.setObject(col, null);
                        }
                    } else {
                        pStmt.setDate(col, null);
                    }
                }
                    break;

                case eTime: {
                    Time time = null;
                    try {
                        time = Time.valueOf(value);
                    } catch (Exception ex) {
                    }
                    pStmt.setTime(col, time);
                }
                    break;

                case eDate: {
                    String origValue = value;
                    try {
                        if (StringUtils.isNotEmpty(value) && !value.equals("?") && !value.equals("-")) {
                            int len = value.length();
                            if (len == 8 && value.charAt(1) == '-' && value.charAt(3) == '-') // 0-9-1886
                            {
                                String dayStr = value.substring(0, 1);
                                String monStr = value.substring(2, 3);
                                if (StringUtils.isNumeric(dayStr) && StringUtils.isNumeric(monStr)) {
                                    String year = value.substring(4);
                                    int day = Integer.parseInt(dayStr);
                                    int mon = Integer.parseInt(monStr);
                                    if (day == 0)
                                        day = 1;
                                    if (mon == 0)
                                        mon = 1;

                                    value = String.format("%02d-%02d-%s", day, mon, year);
                                } else {
                                    value = StringUtils.replaceChars(value, '.', ' ');
                                    String[] toks = StringUtils.split(value, ' ');
                                    if (toks.length == 3) {
                                        String dyStr = toks[0];
                                        String mnStr = toks[1];
                                        String yrStr = toks[2];
                                        if (StringUtils.isNumeric(mnStr) && StringUtils.isNumeric(dyStr)
                                                && StringUtils.isNumeric(yrStr)) {
                                            int day = Integer.parseInt(dyStr);
                                            int mon = Integer.parseInt(mnStr);
                                            int year = Integer.parseInt(yrStr);
                                            if (day == 0)
                                                day = 1;
                                            if (mon == 0)
                                                mon = 1;

                                            value = String.format("%02d-%02d-%04d", day, mon, year);
                                        } else {
                                            System.err.println(
                                                    col + " Bad Date#[" + value + "]  [" + origValue + "]\n");
                                        }
                                    } else {
                                        System.err.println(
                                                col + " Bad Date#[" + value + "]  [" + origValue + "]\n");
                                    }
                                }

                            } else if (len == 8 && (value.charAt(3) == '-' || value.charAt(3) == ' ')) // Apr-1886
                            {
                                String monStr = value.substring(0, 3);
                                Integer month = monthHash.get(monStr);
                                String year = value.substring(4);
                                if (month != null && StringUtils.isNumeric(year)) {
                                    value = String.format("01-%02d-%s", month, year);
                                } else {
                                    value = StringUtils.replaceChars(value, '.', ' ');
                                    String[] toks = StringUtils.split(value, ' ');
                                    if (toks.length == 3) {
                                        String dyStr = toks[0];
                                        String mnStr = toks[1];
                                        String yrStr = toks[2];
                                        if (StringUtils.isNumeric(mnStr) && StringUtils.isNumeric(dyStr)
                                                && StringUtils.isNumeric(yrStr)) {
                                            int day = Integer.parseInt(dyStr);
                                            int mon = Integer.parseInt(mnStr);
                                            int yr = Integer.parseInt(yrStr);
                                            if (day == 0)
                                                day = 1;
                                            if (mon == 0)
                                                mon = 1;

                                            value = String.format("%02d-%02d-%04d", day, mon, yr);
                                        } else {
                                            System.err.println(
                                                    col + " Bad Date#[" + value + "]  [" + origValue + "]\n");
                                        }
                                    } else {
                                        System.err.println(
                                                col + " Bad Date#[" + value + "]  [" + origValue + "]\n");
                                    }
                                }

                            } else if ((len == 11 && value.charAt(2) == '-' && value.charAt(6) == '-') || // 10-May-1898
                                    (len == 10 && value.charAt(1) == '-' && value.charAt(5) == '-')) //  7-May-1898
                            {
                                boolean do11 = len == 11;
                                String dayStr = value.substring(0, do11 ? 2 : 1);
                                String monStr = value.substring(do11 ? 3 : 2, do11 ? 6 : 5);

                                Integer month = monthHash.get(monStr);
                                String year = value.substring(do11 ? 7 : 6);
                                if (month != null && StringUtils.isNumeric(dayStr)
                                        && StringUtils.isNumeric(year)) {
                                    int day = Integer.parseInt(dayStr);
                                    if (day == 0)
                                        day = 1;
                                    value = String.format("%02d-%02d-%s", day, month, year);

                                } else {
                                    System.err
                                            .println(col + " Bad Date^[" + value + "]  [" + origValue + "]\n");
                                }
                            } else if (len == 4) {
                                if (StringUtils.isNumeric(value)) {
                                    value = "01-01-" + value;

                                } else if (value.equalsIgnoreCase("s.d.") || value.equalsIgnoreCase("n.d.")
                                        || value.equalsIgnoreCase("s.n.")) {
                                    value = null;
                                }
                            } else if (StringUtils.contains(value, "/")) {
                                value = StringUtils.replace(value, "/", "-");

                            } else if (StringUtils.contains(value, " ")) {
                                value = StringUtils.replace(value, " ", "-");
                            }
                            pStmt.setDate(col,
                                    StringUtils.isNotEmpty(value)
                                            ? new java.sql.Date(sdf.parse(value).getTime())
                                            : null);
                        } else {
                            pStmt.setDate(col, null);
                        }
                    } catch (Exception ex) {
                        System.err.println(col + " Bad Date[" + value + "]  [" + origValue + "]\n" + str);
                        pStmt.setDate(col, null);
                    }
                }
                    break;

                default: {
                    System.err.println("Col: " + col + "  Error - " + fd.getType());
                }
                }
                inx++;
                col++;
            }
            pStmt.execute();
            str = in.readLine();
            rowCnt++;
            if (rowCnt % 1000 == 0) {
                System.out.println(rowCnt);
            }
        }
        in.close();

    } catch (Exception ex) {
        ex.printStackTrace();

    } finally {
        try {
            stmt.close();
            conn.close();
            pStmt.close();

        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}

From source file:com.aimluck.eip.mail.util.ALMailUtils.java

public static boolean setNotifyTime(int hour, int minute) {
    StringBuffer sb = new StringBuffer();
    if (hour < 10) {
        sb.append("0");
    }//from  ww w .j  a v  a2 s  .com
    sb.append(Integer.toString(hour)).append(":");
    if (minute < 10) {
        sb.append("0");
    }
    sb.append(Integer.toString(minute)).append(":00");
    Time time = Time.valueOf(sb.toString());

    try {
        EipMMailNotifyConf conf = getEipMMailNotifyConf(1);
        if (conf == null) {
            return false;
        }

        conf.setNotifyTime(time);
        Database.commit();
        return true;
    } catch (Throwable t) {
        Database.rollback();
        logger.error("ALMailUtils.setNotifyTime", t);
        return false;
    }
}

From source file:fll.scheduler.TournamentSchedule.java

/**
 * Store a tournament schedule in the database. This will delete any previous
 * schedule for the same tournament./* w  w w  .  j  ava2s. c  o  m*/
 * 
 * @param tournamentID the ID of the tournament
 */
public void storeSchedule(final Connection connection, final int tournamentID) throws SQLException {
    PreparedStatement deletePerfRounds = null;
    PreparedStatement deleteSchedule = null;
    PreparedStatement deleteSubjective = null;
    PreparedStatement insertSchedule = null;
    PreparedStatement insertPerfRounds = null;
    PreparedStatement insertSubjective = null;
    try {
        // delete previous tournament schedule
        deletePerfRounds = connection.prepareStatement("DELETE FROM sched_perf_rounds WHERE tournament = ?");
        deletePerfRounds.setInt(1, tournamentID);
        deletePerfRounds.executeUpdate();

        deleteSubjective = connection.prepareStatement("DELETE FROM sched_subjective WHERE tournament = ?");
        deleteSubjective.setInt(1, tournamentID);
        deleteSubjective.executeUpdate();

        deleteSchedule = connection.prepareStatement("DELETE FROM schedule WHERE tournament = ?");
        deleteSchedule.setInt(1, tournamentID);
        deleteSchedule.executeUpdate();

        // insert new tournament schedule
        insertSchedule = connection.prepareStatement("INSERT INTO schedule"//
                + " (tournament, team_number, judging_station)"//
                + " VALUES(?, ?, ?)");
        insertSchedule.setInt(1, tournamentID);

        insertPerfRounds = connection.prepareStatement("INSERT INTO sched_perf_rounds"//
                + " (tournament, team_number, round, perf_time, table_color, table_side)"//
                + " VALUES(?, ?, ?, ?, ?, ?)");
        insertPerfRounds.setInt(1, tournamentID);

        insertSubjective = connection.prepareStatement("INSERT INTO sched_subjective" //
                + " (tournament, team_number, name, subj_time)" //
                + " VALUES(?, ?, ?, ?)");
        insertSubjective.setInt(1, tournamentID);

        for (final TeamScheduleInfo si : getSchedule()) {
            insertSchedule.setInt(2, si.getTeamNumber());
            insertSchedule.setString(3, si.getJudgingGroup());
            insertSchedule.executeUpdate();

            insertPerfRounds.setInt(2, si.getTeamNumber());
            for (int round = 0; round < si.getNumberOfRounds(); ++round) {
                insertPerfRounds.setInt(3, round);
                insertPerfRounds.setTime(4, Time.valueOf(si.getPerfTime(round)));
                insertPerfRounds.setString(5, si.getPerfTableColor(round));
                insertPerfRounds.setInt(6, si.getPerfTableSide(round));
                insertPerfRounds.executeUpdate();
            }

            for (final SubjectiveTime subjectiveTime : si.getSubjectiveTimes()) {
                insertSubjective.setInt(2, si.getTeamNumber());
                insertSubjective.setString(3, subjectiveTime.getName());
                insertSubjective.setTime(4, Time.valueOf(subjectiveTime.getTime()));
                insertSubjective.executeUpdate();
            }
        }

    } finally {
        SQLFunctions.close(deletePerfRounds);
        deletePerfRounds = null;
        SQLFunctions.close(deleteSchedule);
        deleteSchedule = null;
        SQLFunctions.close(deleteSubjective);
        deleteSubjective = null;
        SQLFunctions.close(insertSchedule);
        insertSchedule = null;
        SQLFunctions.close(insertPerfRounds);
        insertPerfRounds = null;
        SQLFunctions.close(insertSubjective);
        insertSubjective = null;
    }
}

From source file:adalid.core.AbstractDataArtifact.java

private Time someTimeValue(Field field, String string) {
    if (StringUtils.isBlank(string)) {
        return null;
    }// www . ja v a 2s. c o  m
    Time someRelativeTime = someRelativeTimeValue(string);
    if (someRelativeTime != null) {
        return someRelativeTime;
    }
    try {
        return Time.valueOf(string);
    } catch (Exception e) {
        logInvalidDataExpression(field, "time", e);
    }
    return null;
}

From source file:net.unicon.sakora.impl.csv.CsvSectionMeetingHandler.java

@Override
protected void readInputLine(CsvSyncContext context, String[] line) {

    final int minFieldCount = 6;

    if (line != null && line.length >= minFieldCount) {
        line = trimAll(line);/*from   w w  w .  ja  v  a  2s . c om*/

        // for clarity
        String eid = line[0]; // section EID
        String location = line[1];
        String notes = line[2];
        Time startTime = null;
        Time endTime = null;
        if (line.length == 5) {
            startTime = Time.valueOf(line[3]);
            endTime = Time.valueOf(line[4]);
        }

        if (!isValid(location, "Location", eid) || !isValid(startTime, "Start Time", eid)
                || !isValid(endTime, "End Time", eid)) {
            log.error("Missing required parameter(s), skipping item " + eid);
            errors++;
        } else {
            if (commonHandlerService.processSection(eid)) {
                if (cmService.isSectionDefined(eid)) {
                    Section section = cmService.getSection(eid);
                    Meeting meeting = cmAdmin.newSectionMeeting(eid, location, startTime, endTime, notes);
                    if (!section.getMeetings().contains(meeting)) {
                        section.getMeetings().add(meeting);
                        adds++;
                    }
                    cmAdmin.updateSection(section);
                } else {
                    log.error("CsvSectionMeetingHandler :: can't add meeting to invalid section");
                }
            } else {
                if (log.isDebugEnabled())
                    log.debug("Skipped processing course section meeting because it is in a section (" + eid
                            + ") which is part of an academic session which is being skipped");
            }
        }
    } else {
        log.error("Skipping short line (expected at least [" + minFieldCount + "] fields): ["
                + (line == null ? null : Arrays.toString(line)) + "]");
        errors++;
    }
}