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


Java Connection.prepareStatement方法代码示例

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


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

示例1: getSettings

import java.sql.Connection; //导入方法依赖的package包/类
@Override
public Settings getSettings(Connection txn, String namespace)
		throws DbException {
	PreparedStatement ps = null;
	ResultSet rs = null;
	try {
		String sql = "SELECT key, value FROM settings WHERE namespace = ?";
		ps = txn.prepareStatement(sql);
		ps.setString(1, namespace);
		rs = ps.executeQuery();
		Settings s = new Settings();
		while (rs.next()) s.put(rs.getString(1), rs.getString(2));
		rs.close();
		ps.close();
		return s;
	} catch (SQLException e) {
		tryToClose(rs);
		tryToClose(ps);
		throw new DbException(e);
	}
}
 
开发者ID:rafjordao,项目名称:Nird2,代码行数:22,代码来源:JdbcDatabase.java

示例2: testBug75956

import java.sql.Connection; //导入方法依赖的package包/类
/**
 * Test Bug#75956 - Inserting timestamps using a server PreparedStatement and useLegacyDatetimeCode=false
 */
public void testBug75956() throws Exception {
    createTable("bug75956", "(id int not null primary key auto_increment, dt1 datetime, dt2 datetime)");
    Connection sspsConn = getConnectionWithProps("useCursorFetch=true,useLegacyDatetimeCode=false");
    this.pstmt = sspsConn.prepareStatement("insert into bug75956 (dt1, dt2) values (?, ?)");
    this.pstmt.setTimestamp(1, new Timestamp(System.currentTimeMillis()));
    this.pstmt.setTimestamp(2, new Timestamp(System.currentTimeMillis()));
    this.pstmt.addBatch();
    this.pstmt.clearParameters();
    this.pstmt.setTimestamp(1, new Timestamp(System.currentTimeMillis()));
    this.pstmt.setTimestamp(2, null);
    this.pstmt.addBatch();
    this.pstmt.setTimestamp(1, new Timestamp(System.currentTimeMillis()));
    this.pstmt.setTimestamp(2, new Timestamp(System.currentTimeMillis()));
    this.pstmt.addBatch();
    this.pstmt.executeBatch();
    this.pstmt.close();
    this.rs = sspsConn.createStatement().executeQuery("select count(*) from bug75956 where dt2 is NULL");
    this.rs.next();
    assertEquals(1, this.rs.getInt(1));
    sspsConn.close();
}
 
开发者ID:rafallis,项目名称:BibliotecaPS,代码行数:25,代码来源:StatementRegressionTest.java

示例3: inspectContainer

import java.sql.Connection; //导入方法依赖的package包/类
public synchronized void inspectContainer(Player p, UUID world, Vector3i pos) {
	Connection c = db.getConnection();
	ContainerLookupResult lookup = null;
	
	try {
		PreparedStatement ps = c.prepareStatement(QueryHelper.INSPECT_CONTAINER_QUERY);
		ps.setInt(1, pos.getX());
		ps.setInt(2, pos.getY());
		ps.setInt(3, pos.getZ());
		ps.setString(4, world.toString());
		ResultSet result = ps.executeQuery();
		
		lookup = new ContainerLookupResult(result);
		LookupResultManager.instance().setLookupResult(p, lookup);
		
		result.close();
		c.close();
	} catch (SQLException e) {
		e.printStackTrace();
		p.sendMessage(Text.of(TextColors.DARK_AQUA, "[AC] ", TextColors.RED, "A database error has occurred! Contact your server administrator!"));
		return;
	}
	
	lookup.showPage(p, 1);
}
 
开发者ID:Karanum,项目名称:AdamantineShield,代码行数:26,代码来源:InspectManager.java

示例4: inserir

import java.sql.Connection; //导入方法依赖的package包/类
@Override
public String inserir(Professor professor, String texto) {
    String sql = "insert into mural (texto, id_prof) values (?,?)";
    Connection conn = SQLiteConnectionFactory.getConnection();
    
    try{
        PreparedStatement pst = conn.prepareStatement(sql);
        pst.setString(1,texto);
        pst.setInt(2,professor.getId());
        
        int res = pst.executeUpdate();
        if(res > 0){
            return "Conteudo salvo com sucesso!";
        }else{
            return "Erro ao inserir conteudo";
        }
    }catch(SQLException e){
        return e.getMessage();
    }finally{
        SQLiteConnectionFactory.close(conn);
    }
    
}
 
开发者ID:TheMagicFingers,项目名称:MuralEscolar,代码行数:24,代码来源:MuralDAOImp.java

示例5: getAmount

import java.sql.Connection; //导入方法依赖的package包/类
/**
   * Get the number of incident for a specific component in the table.
   */
  public int getAmount(String component, int id) throws SQLException {
      Connection connection = dataSource.getConnection();
      ResultSet rs = null;
      
      try {
          PreparedStatement pstmt = connection
                  .prepareStatement("SELECT " + component
                  				+ " FROM ROOT"
                  				+ " WHERE ID=?");
          pstmt.setInt(1, id);
          rs = pstmt.executeQuery();

          if (rs.next()) {
          	return rs.getInt(1);
          }
      } finally {
          if (connection != null) {
              connection.close();
          }
      }
return -1;
  }
 
开发者ID:qianyilun,项目名称:Queue-Manager-Cloud-Dispatcher,代码行数:26,代码来源:TemplateDAO.java

示例6: selectTriggerListeners

import java.sql.Connection; //导入方法依赖的package包/类
/**
 * <p>
 * Select the listeners associated with a given trigger.
 * </p>
 * 
 * @param conn
 *          the DB Connection
 * @param triggerName
 *          the name of the trigger
 * @param groupName
 *          the group containing the trigger
 * @return array of <code>String</code> trigger listener names
 */
public String[] selectTriggerListeners(Connection conn, String triggerName,
        String groupName) throws SQLException {
    PreparedStatement ps = null;
    ResultSet rs = null;

    try {
        ps = conn.prepareStatement(rtp(SELECT_TRIGGER_LISTENERS));
        ps.setString(1, triggerName);
        ps.setString(2, groupName);
        rs = ps.executeQuery();

        ArrayList list = new ArrayList();
        while (rs.next()) {
            list.add(rs.getString(1));
        }
        Object[] oArr = list.toArray();
        String[] sArr = new String[oArr.length];
        System.arraycopy(oArr, 0, sArr, 0, oArr.length);
        return sArr;
    } finally {
        closeResultSet(rs);
        closeStatement(ps);
    }
}
 
开发者ID:AsuraTeam,项目名称:asura,代码行数:38,代码来源:StdJDBCDelegate.java

示例7: selectJobExecutionCount

import java.sql.Connection; //导入方法依赖的package包/类
public int selectJobExecutionCount(Connection conn, String jobName,
        String jobGroup) throws SQLException {
    PreparedStatement ps = null;
    ResultSet rs = null;

    try {
        ps = conn.prepareStatement(rtp(SELECT_JOB_EXECUTION_COUNT));
        ps.setString(1, jobName);
        ps.setString(2, jobGroup);

        rs = ps.executeQuery();

        return (rs.next()) ? rs.getInt(1) : 0;
    } finally {
        closeResultSet(rs);
        closeStatement(ps);
    }
}
 
开发者ID:AsuraTeam,项目名称:asura,代码行数:19,代码来源:StdJDBCDelegate.java

示例8: setPandoraLog

import java.sql.Connection; //导入方法依赖的package包/类
public void setPandoraLog(String itemid) {
Connection con1 = DatabaseConnection.getConnection();
try {
PreparedStatement ps;
ps = con1.prepareStatement("insert into pandoralog (characterid, itemid) values (?,?)");
ps.setInt(1, id);
ps.setString(2, itemid);
ps.executeUpdate();
ps.close();
} catch (Exception Ex) {
	System.out.print("Error setting the Pandora Log.");
}
}
 
开发者ID:NovaStory,项目名称:AeroStory,代码行数:14,代码来源:MapleCharacter.java

示例9: UserHelper

import java.sql.Connection; //导入方法依赖的package包/类
/**
 * Constructor which makes a connection
 */
public UserHelper() {
	try {
		//Set up connection
		Class.forName("com.mysql.jdbc.Driver");
		//CHECK HERE FOR CONNECTION PROBLEM
		Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/chemistrydatabase", "root", "root");
		
		//Create the preparedstatement(s)
		authenticateUserStatement = conn.prepareStatement("select * from user where email=? and password=?");
	} catch (Exception e) {
		System.out.println(e.getClass().getName() + ": " + e.getMessage());
	}
}
 
开发者ID:theBusBoy,项目名称:ChemistryAdministrativePortal,代码行数:17,代码来源:UserHelper.java

示例10: createInsertStatement

import java.sql.Connection; //导入方法依赖的package包/类
/**
 * Create a {@link PreparedStatement} for an INSERT operation configuring generated keys.
 * @param connection Connection
 * @param dialect Dialect
 * @param sql SQL statement
 * @param pkNames Optional primary key column names
 * @return Configured statement
 * @throws SQLException If an error occurred
 */
private PreparedStatement createInsertStatement(Connection connection, JdbcDialect dialect, String sql,
		String[] pkNames) throws SQLException {
	if (dialect.supportsGetGeneratedKeys()) {
		if (getDialect().supportGetGeneratedKeyByName() && pkNames != null && pkNames.length > 0) {
			return connection.prepareStatement(sql, pkNames);
		} else {
			return connection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
		}
	}
	return connection.prepareStatement(sql);
}
 
开发者ID:holon-platform,项目名称:holon-datastore-jdbc,代码行数:21,代码来源:DefaultJdbcDatastore.java

示例11: insertBilibiliData

import java.sql.Connection; //导入方法依赖的package包/类
public static void insertBilibiliData(Connection conn, Bilibili bilibili) throws SQLException{
	String insertSQL = "INSERT INTO bilibili (aid,tid,title,tname,favorite,coin,author) VALUES (?,?,?,?,?,?,?)";
	PreparedStatement ps = conn.prepareStatement(insertSQL);
	ps.setInt(1, bilibili.getAid());
	ps.setInt(2, bilibili.getTid());
	ps.setString(3, bilibili.getTitle());
	ps.setString(4, bilibili.getTname());
	ps.setInt(5, bilibili.getFavorite());
	ps.setInt(6, bilibili.getCoin());
	ps.setString(7, bilibili.getAuthor());
	ps.execute();
}
 
开发者ID:bighuang624,项目名称:BiliInfoCrawler,代码行数:13,代码来源:JDBC.java

示例12: insert

import java.sql.Connection; //导入方法依赖的package包/类
/**
 * Insert a new CallLog into the database
 *
 * @param callLog call logging
 * @throws SQLException
 */
public static void insert(CallLog callLog) throws SQLException {

    String sql = "INSERT INTO ofSipPhoneLog (username, addressFrom, addressTo, datetime, duration, calltype) "
            + " values  (?, ?, ?, ?, ?, ?)";

    Connection con = null;
    PreparedStatement psmt = null;
    ResultSet rs = null;

    try {
        con = DbConnectionManager.getConnection();
        psmt = con.prepareStatement(sql);
        psmt.setString(1, callLog.getUsername());
        psmt.setString(2, callLog.getNumA());
        psmt.setString(3, callLog.getNumB());
        psmt.setLong(4, callLog.getDateTime());
        psmt.setInt(5, callLog.getDuration());
        psmt.setString(6, callLog.getType().name());

        psmt.executeUpdate();

    } catch (SQLException e) {
        Log.error(e.getMessage(), e);
        throw new SQLException(e.getMessage());
    } finally {
        DbConnectionManager.closeConnection(rs, psmt, con);
    }

}
 
开发者ID:igniterealtime,项目名称:ofmeet-openfire-plugin,代码行数:36,代码来源:CallLogDAO.java

示例13: updateTipoDocumento

import java.sql.Connection; //导入方法依赖的package包/类
public static boolean updateTipoDocumento(TipoDocumento tipoDocumento,String usuarioResponsable) {
	try {
		Connection conect = ConnectionConfiguration.conectar();

		String query = "update tipo_documentos set ";
		PreparedStatement update = null;
		
		if (tipoDocumento.getNombre() != "") {
			query += " nombre = ?, ";
		}
		{
			query += " usuario_responsable = ?, ";
		}

		query = query.substring(0, query.length() - 2);
		query += " where id = ?";

		int cantCampos = 0;
		update = conect.prepareStatement(query);
		
		if (tipoDocumento.getNombre() != "") {
			cantCampos++;
			update.setString(cantCampos, tipoDocumento.getNombre());
		}
		cantCampos++;
		update.setString(cantCampos, usuarioResponsable);

		cantCampos++;
		update.setInt(cantCampos, tipoDocumento.getId());

		update.execute();
		conect.close();
		return true;
	} catch (SQLException e) {
		e.printStackTrace();
		return false;
	}
}
 
开发者ID:stppy,项目名称:spr,代码行数:39,代码来源:SqlUpdates.java

示例14: selectAll

import java.sql.Connection; //导入方法依赖的package包/类
public List<Map<String, Object>> selectAll(Connection connection, String sql, List<Object> args) throws SQLException {
	PreparedStatement ps = connection.prepareStatement(sql);
	try {
		setParameters(ps, args);
		ResultSet rs = ps.executeQuery();
		return getResults(rs, null);
	} finally {
		try {
			ps.close();
		} catch (SQLException e) {
			// ignore
		}
	}
}
 
开发者ID:xsonorg,项目名称:tangyuan2,代码行数:15,代码来源:SqlActuator.java

示例15: isNoticeEnabled

import java.sql.Connection; //导入方法依赖的package包/类
/**
 * @return Returns the noticeEnabled.
 */
public boolean isNoticeEnabled()
{
 String result="";
 Connection con = null;
 try
 {
    
	 con = L2DatabaseFactory.getInstance().getConnection();
	 PreparedStatement statement = con.prepareStatement("SELECT enabled FROM clan_notices WHERE clanID=?");
	 statement.setInt(1, getClanId());
	 ResultSet rset = statement.executeQuery();
    
	 while (rset.next())
	 {
		 result = rset.getString("enabled");
	 }
    
	 rset.close();
	 statement.close();
	 con.close();
    
 } catch (Exception e)
 {
	 if (Config.DEBUG)
	 System.out.println("BBS: Error while reading _noticeEnabled for clan "+ this.getClanId() + "");
	 if(e.getMessage()!=null)
		 if (Config.DEBUG) 
		 System.out.println("BBS: Exception = "+e.getMessage()+"");
 }
 if (result.isEmpty())
 {
	 insertNotice();
	 return false;
 }
 else if(result.compareToIgnoreCase("true")==0)
	 return true;
 else
	 return false;
}
 
开发者ID:L2jBrasil,项目名称:L2jBrasil,代码行数:43,代码来源:L2Clan.java


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