当前位置: 首页>>代码示例>>Java>>正文


Java PreparedStatement.setLong方法代码示例

本文整理汇总了Java中java.sql.PreparedStatement.setLong方法的典型用法代码示例。如果您正苦于以下问题:Java PreparedStatement.setLong方法的具体用法?Java PreparedStatement.setLong怎么用?Java PreparedStatement.setLong使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.sql.PreparedStatement的用法示例。


在下文中一共展示了PreparedStatement.setLong方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: addOperations

import java.sql.PreparedStatement; //导入方法依赖的package包/类
private void addOperations(PreparedStatement statement, long testId, String version, MeasuredOperationList operations) throws SQLException {
    for (MeasuredOperation operation : operations) {
        statement.setLong(1, testId);
        statement.setString(2, version);
        statement.setBigDecimal(3, operation.getTotalTime().toUnits(Duration.MILLI_SECONDS).getValue());
        statement.setBigDecimal(4, operation.getConfigurationTime().toUnits(Duration.MILLI_SECONDS).getValue());
        statement.setBigDecimal(5, operation.getExecutionTime().toUnits(Duration.MILLI_SECONDS).getValue());
        statement.setBigDecimal(6, operation.getTotalMemoryUsed().toUnits(DataAmount.BYTES).getValue());
        statement.setBigDecimal(7, operation.getTotalHeapUsage().toUnits(DataAmount.BYTES).getValue());
        statement.setBigDecimal(8, operation.getMaxHeapUsage().toUnits(DataAmount.BYTES).getValue());
        statement.setBigDecimal(9, operation.getMaxUncollectedHeap().toUnits(DataAmount.BYTES).getValue());
        statement.setBigDecimal(10, operation.getMaxCommittedHeap().toUnits(DataAmount.BYTES).getValue());
        if (operation.getCompileTotalTime() != null) {
            statement.setBigDecimal(11, operation.getCompileTotalTime().toUnits(Duration.MILLI_SECONDS).getValue());
        } else {
            statement.setNull(11, Types.DECIMAL);
        }
        if (operation.getGcTotalTime() != null) {
            statement.setBigDecimal(12, operation.getGcTotalTime().toUnits(Duration.MILLI_SECONDS).getValue());
        } else {
            statement.setNull(12, Types.DECIMAL);
        }
        statement.addBatch();
    }
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:26,代码来源:CrossVersionResultsStore.java

示例2: addPermission

import java.sql.PreparedStatement; //导入方法依赖的package包/类
/**
 * Adds a permission entry.
 * @param target the permission target.
 * @param permission the permission to add.
 * @return {@code false} if there already is an entry for {@code permission} and {@code target}.
 */
public boolean addPermission(PermissionTarget target, Permission permission) {
    if(hasPermission(target, permission, true))
        return false;
    try {
        PreparedStatement insertStatement = MySQL.getConnection()
                .prepareStatement("INSERT INTO `" + TABLE + "` " +
                        "(`guildid`, `type`, `id`, `permission`, `negated`) VALUES (?, ?, ?, ?, ?)");
        insertStatement.setLong(1, target.getGuild().getIdLong());
        insertStatement.setString(2, String.valueOf(target.getType().getIdentifier()));
        insertStatement.setLong(3, target.getId());
        insertStatement.setString(4, permission.getPermissionString());
        insertStatement.setBoolean(5, permission.isNegated());
        insertStatement.execute();
        return true;
    } catch (SQLException e) {
        throw new RuntimeException("An unknown error has occurred while saving data to the database.", e);
    }
}
 
开发者ID:Rubicon-Bot,项目名称:Rubicon,代码行数:25,代码来源:PermissionManager.java

示例3: insertNumeric

import java.sql.PreparedStatement; //导入方法依赖的package包/类
public static void insertNumeric() throws ClassNotFoundException, SQLException {
    Class.forName("com.mysql.jdbc.Driver");
    Properties from = new Properties();
    from.put("user", "root");
    from.put("password", "root");
    from.put("characterEncoding", "utf8");
    Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/erosa", from);
    PreparedStatement pst = conn.prepareStatement("insert into unsignednumeric(id,id1,id2,id3) values (?,?,?,?)");
    pst.setLong(1, Integer.MAX_VALUE * 2L);
    pst.setLong(2, Integer.MIN_VALUE);
    pst.setBigDecimal(3, new BigDecimal("18446744073709551614"));
    pst.setBigDecimal(4, new BigDecimal(Long.MIN_VALUE + ""));
    pst.executeUpdate();

    pst.close();
    conn.close();
}
 
开发者ID:luoyaogui,项目名称:otter-G,代码行数:18,代码来源:TestMysqlUnsignedNumber.java

示例4: saveToDb

import java.sql.PreparedStatement; //导入方法依赖的package包/类
/**
 * Saves a bookmark to the database.
 */
private void saveToDb() {
    Connection con = null;
    boolean abortTransaction = false;
    try {
        con = DbConnectionManager.getTransactionConnection();
        PreparedStatement pstmt = con.prepareStatement(SAVE_BOOKMARK);
        pstmt.setString(1, type.toString());
        pstmt.setString(2, name);
        pstmt.setString(3, value);
        pstmt.setInt(4, global ? 1 : 0);
        pstmt.setLong(5, bookmarkID);
        pstmt.executeUpdate();
        pstmt.close();
    }
    catch (SQLException sqle) {
        abortTransaction = true;
        Log.error(sqle.getMessage(), sqle);
    }
    finally {
        DbConnectionManager.closeTransactionConnection(con, abortTransaction);
    }
}
 
开发者ID:igniterealtime,项目名称:ofmeet-openfire-plugin,代码行数:26,代码来源:Bookmark.java

示例5: deletePropertyFromDb

import java.sql.PreparedStatement; //导入方法依赖的package包/类
/**
 * Deletes a property from the db.
 */
private synchronized void deletePropertyFromDb(String name) {
    Connection con = null;
    PreparedStatement pstmt = null;
    boolean abortTransaction = false;
    try {
        con = DbConnectionManager.getTransactionConnection();
        pstmt = con.prepareStatement(DELETE_PROPERTY);
        pstmt.setLong(1, bookmarkID);
        pstmt.setString(2, name);
        pstmt.execute();
    }
    catch (SQLException sqle) {
        Log.error(sqle.getMessage(), sqle);
        abortTransaction = true;
    }
    finally {
        DbConnectionManager.closeTransactionConnection(pstmt, con, abortTransaction);
    }
}
 
开发者ID:igniterealtime,项目名称:ofmeet-openfire-plugin,代码行数:23,代码来源:Bookmark.java

示例6: incrementStreamCounter

import java.sql.PreparedStatement; //导入方法依赖的package包/类
@Override
public void incrementStreamCounter(Connection txn, ContactId c,
		TransportId t, long rotationPeriod) throws DbException {
	PreparedStatement ps = null;
	try {
		String sql = "UPDATE outgoingKeys SET stream = stream + 1"
				+ " WHERE contactId = ? AND transportId = ? AND period = ?";
		ps = txn.prepareStatement(sql);
		ps.setInt(1, c.getInt());
		ps.setString(2, t.getString());
		ps.setLong(3, rotationPeriod);
		int affected = ps.executeUpdate();
		if (affected != 1) throw new DbStateException();
		ps.close();
	} catch (SQLException e) {
		tryToClose(ps);
		throw new DbException(e);
	}
}
 
开发者ID:rafjordao,项目名称:Nird2,代码行数:20,代码来源:JdbcDatabase.java

示例7: insertTestData

import java.sql.PreparedStatement; //导入方法依赖的package包/类
private void insertTestData() throws Exception {

//        conn.createStatement().executeUpdate("INSERT INTO \"SITE_LIST_SITE\" VALUES(23,1,'ru','RU',NULL,'\u041f\u0440\u043e\u0431\u043d\u044b\u0439 \u0441\u0430\u0439\u0442',NULL,0,'''/front_styles.css''',1,NULL,0)");
//        conn.createStatement().executeUpdate("INSERT INTO \"SITE_VIRTUAL_HOST\" VALUES(36,23,'test-host')");
//        conn.createStatement().executeUpdate("INSERT INTO \"SITE_SUPPORT_LANGUAGE\" VALUES(115,23,1,'ru_RU','ru_RU')");
//        conn.createStatement().executeUpdate("INSERT INTO \"CASH_CURRENCY\" VALUES(134,'\u0420\u0443\u0431',1,'\u0420\u0443\u0431',0,3,23,0.0)");
//        conn.createStatement().executeUpdate("INSERT INTO \"CASH_CURRENCY\" VALUES(135,'EURO',1,'EURO',0,7,23,0.0)");
        conn.createStatement().executeUpdate(
            "INSERT INTO \"CASH_CURRENCY\" VALUES(134,23)");
        conn.createStatement().executeUpdate(
            "INSERT INTO \"CASH_CURRENCY\" VALUES(135,23)");

        PreparedStatement ps = conn.prepareStatement("insert into "
            + nameTable + "(T, ID) values (?, ?)");

        ps.setTimestamp(1, testTS);
        ps.setLong(2, id);
        ps.executeUpdate();
        ps.close();

        ps = null;

        conn.commit();
    }
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:25,代码来源:TestTimestamp.java

示例8: updateSubscriptionKey

import java.sql.PreparedStatement; //导入方法依赖的package包/类
private void updateSubscriptionKey(long tkey, String subscriptionId,
        long organizationobjkey, long pmKey) throws Exception {
    StringBuffer sb = new StringBuffer();
    sb.append("UPDATE billingresult SET subscriptionkey=");
    sb.append("(SELECT DISTINCT objkey FROM subscriptionhistory sh WHERE ");
    sb.append("sh.subscriptionid=? AND organizationobjkey=?");
    sb.append(" AND (select distinct pricemodelobjkey from producthistory prdh where prdh.objkey=sh.productobjkey and ?=prdh.pricemodelobjkey) is not null) ");
    sb.append("WHERE tkey=?");

    PreparedStatement pStatement = null;
    try {
        pStatement = getPreparedStatement(sb.toString());
        pStatement.setString(1, subscriptionId);
        pStatement.setLong(2, organizationobjkey);
        pStatement.setLong(3, pmKey);
        pStatement.setLong(4, tkey);
        pStatement.executeUpdate();
    } finally {
        closeStatement(pStatement, null);
    }
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:22,代码来源:MigrationBillingResultAttributes.java

示例9: updatePropertyInDb

import java.sql.PreparedStatement; //导入方法依赖的package包/类
/**
 * Updates a property value in the database.
 */
private void updatePropertyInDb(String name, String value) {
    Connection con = null;
    PreparedStatement pstmt = null;
    boolean abortTransaction = false;
    try {
        con = DbConnectionManager.getTransactionConnection();
        pstmt = con.prepareStatement(UPDATE_PROPERTY);
        pstmt.setString(1, value);
        pstmt.setString(2, name);
        pstmt.setLong(3, bookmarkID);
        pstmt.executeUpdate();
    }
    catch (SQLException sqle) {
        Log.error(sqle.getMessage(), sqle);
        abortTransaction = true;
    }
    finally {
        DbConnectionManager.closeTransactionConnection(pstmt, con, abortTransaction);
    }
}
 
开发者ID:igniterealtime,项目名称:ofmeet-openfire-plugin,代码行数:24,代码来源:Bookmark.java

示例10: prepareStatement

import java.sql.PreparedStatement; //导入方法依赖的package包/类
/**
 * Creates a prepared statement with given properties
 * @param  sql   The SQL query
 * @param  args  The query values
 * @return  The prepared statement
 */
protected PreparedStatement prepareStatement(String sql, Object... args) throws SQLException {
	if (!isConnected()) return null;
	PreparedStatement statement = connection.prepareStatement(sql);
	
	if (args != null && args.length > 0) {
		for (int i = 0; i < args.length; i++) {
			if (args[i] instanceof String) statement.setString(i + 1, (String) args[i]);
			else if (args[i] instanceof Integer) statement.setInt(i + 1, (int) args[i]);
			else if (args[i] instanceof Long) statement.setLong(i + 1, (long) args[i]);
			else if (args[i] instanceof Boolean) statement.setBoolean(i + 1, (boolean) args[i]);
			else if (WurmMapGen.debug)
				throw new RuntimeException("Unknown type " + (args[i].getClass().getName()) + " in prepared statement");
		}
	}
	
	return statement;
}
 
开发者ID:woubuc,项目名称:WurmMapGen,代码行数:24,代码来源:DatabaseConnection.java

示例11: updateActivity

import java.sql.PreparedStatement; //导入方法依赖的package包/类
private void updateActivity(Connection conn) throws SQLException {
PreparedStatement stmt = null;
try {
    stmt = conn.prepareStatement(
	    "UPDATE lams_learning_activity SET language_file = ? WHERE learning_library_id  = ?");
    stmt.setString(1, languageFilename);
    stmt.setLong(2, activityId);
    stmt.execute();
} finally {
    DbUtils.closeQuietly(stmt);
}

   }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:14,代码来源:ActivityDBLanguageUpdateTask.java

示例12: setSchemaVersion

import java.sql.PreparedStatement; //导入方法依赖的package包/类
private static void setSchemaVersion(long version) throws SQLException
{
	PreparedStatement statement = prepare("UPDATE meta SET version = ?");
	try
	{
		statement.setLong(1, version);
		statement.executeUpdate();
	}
	finally
	{
		statement.close();
	}
}
 
开发者ID:PolyphasicDevTeam,项目名称:NapBot,代码行数:14,代码来源:NapBotDb.java

示例13: testAny

import java.sql.PreparedStatement; //导入方法依赖的package包/类
public void testAny() {

        try {
            String ddl =
                "drop table PRICE_RELATE_USER_ORDER_V2 if exists;"
                + "create table PRICE_RELATE_USER_ORDER_V2 "
                + "(ID_ORDER_V2 BIGINT, ID_USER NUMERIC, DATE_CREATE TIMESTAMP)";
            String sql = "insert into PRICE_RELATE_USER_ORDER_V2 "
                         + "(ID_ORDER_V2, ID_USER, DATE_CREATE) " + "values "
                         + "(?, ?, ?)";
            Statement st = connection.createStatement();

            st.execute(ddl);

            PreparedStatement ps = connection.prepareStatement(sql);

            ps.setLong(1, 1);
            ps.setNull(2, Types.NUMERIC);
            ps.setTimestamp(
                3, new java.sql.Timestamp(System.currentTimeMillis()));
            ps.execute();
        } catch (SQLException e) {
            e.printStackTrace();
            System.out.println("TestSql.testAny() error: " + e.getMessage());
        }

        System.out.println("testAny complete");
    }
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:29,代码来源:TestSql.java

示例14: updateExpiryTime

import java.sql.PreparedStatement; //导入方法依赖的package包/类
@Override
public void updateExpiryTime(Connection txn, ContactId c, MessageId m,
		int maxLatency) throws DbException {
	PreparedStatement ps = null;
	ResultSet rs = null;
	try {
		String sql = "SELECT txCount FROM statuses"
				+ " WHERE messageId = ? AND contactId = ?";
		ps = txn.prepareStatement(sql);
		ps.setBytes(1, m.getBytes());
		ps.setInt(2, c.getInt());
		rs = ps.executeQuery();
		if (!rs.next()) throw new DbStateException();
		int txCount = rs.getInt(1);
		if (rs.next()) throw new DbStateException();
		rs.close();
		ps.close();
		sql = "UPDATE statuses SET expiry = ?, txCount = txCount + 1"
				+ " WHERE messageId = ? AND contactId = ?";
		ps = txn.prepareStatement(sql);
		long now = clock.currentTimeMillis();
		ps.setLong(1, calculateExpiry(now, maxLatency, txCount));
		ps.setBytes(2, m.getBytes());
		ps.setInt(3, c.getInt());
		int affected = ps.executeUpdate();
		if (affected != 1) throw new DbStateException();
		ps.close();
	} catch (SQLException e) {
		tryToClose(rs);
		tryToClose(ps);
		throw new DbException(e);
	}
}
 
开发者ID:rafjordao,项目名称:Nird2,代码行数:34,代码来源:JdbcDatabase.java

示例15: updateBillingSharesResultTable

import java.sql.PreparedStatement; //导入方法依赖的package包/类
protected void updateBillingSharesResultTable(String tkey,
        String migratedXml) throws Exception {
    String sql = String.format("UPDATE %s SET %s=? WHERE tkey=?;",
            TABLE_BILLINGSHARESRESULT, COLUMN_RESULTXML);
    PreparedStatement stmt = getPreparedStatement(sql);
    stmt.setString(1, migratedXml);
    stmt.setLong(2, Long.parseLong(tkey));
    stmt.executeUpdate();
    stmt.close();
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:11,代码来源:DatabaseUpgradeTask.java


注:本文中的java.sql.PreparedStatement.setLong方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。