本文整理汇总了Java中com.mysql.jdbc.Statement类的典型用法代码示例。如果您正苦于以下问题:Java Statement类的具体用法?Java Statement怎么用?Java Statement使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Statement类属于com.mysql.jdbc包,在下文中一共展示了Statement类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doInsert
import com.mysql.jdbc.Statement; //导入依赖的package包/类
@Override
/**
* @Title: doInsert
* @Description: Insert a piece of new Content Info
* @param content
* @return boolean
* @throws Exception
*/
public int doInsert(int UrlID, String Html, String Delta) throws Exception {
String query = "insert into Content (UrlID,Html,Delta) values(?,?,?)";
ps = conn.prepareStatement(query, Statement.RETURN_GENERATED_KEYS);
ps.setInt(1, UrlID);
ps.setString(2, Html);
ps.setString(3, Delta);
if(ps.executeUpdate() == 0){
ps.close();
return -1;
}
ResultSet rs = ps.getGeneratedKeys();
rs.next();
int ContentID = rs.getInt(1);
rs.close();ps.close();
return ContentID;
}
示例2: doFindAllChanged
import com.mysql.jdbc.Statement; //导入依赖的package包/类
@Override
/**
*
* @Title: doFindAllChanged
* @Description: ͨ查找所有更新了Delta的Content,返回Content的LinkedList
* @return LinkedList<Content>
* @throws Exception
*/
public LinkedList<Content> doFindAllChanged() throws Exception{
String query = "select * from Content where Delta!=\"\"";
Statement stat = (Statement) conn.createStatement();
ResultSet rs = stat.executeQuery(query);
LinkedList<Content> result = new LinkedList<Content>();
while(rs.next()){
Content newContent = new Content();
newContent.setContentID(rs.getInt(1));
newContent.setUrlID(rs.getInt(2));
newContent.setHtml(rs.getString(3));
newContent.setDelta(rs.getString(4));
result.add(newContent);
}
rs.close();stat.close();
return result;
}
示例3: doFindAllEnabledAndRealTimePush
import com.mysql.jdbc.Statement; //导入依赖的package包/类
@Override
/**
*
* @Title: doFindAllEnabledAndRealTimePush
* @Description: 发现所有激活状态同时是实时推送的Url
* @return Map<Integer, String>
* @throws SQLException
*/
public Map<Integer, String> doFindAllEnabledAndRealTimePush() throws SQLException {
String query = "select UrlID,UserName from Url where Enabled=true and RealTimePush=true";
Statement stat = (Statement) conn.createStatement();
ResultSet rs = stat.executeQuery(query);
Map<Integer,String> urlMap= new HashMap<Integer,String>();
while(rs.next()){
int UrlID = rs.getInt(1);
String UserName = rs.getString(2);
urlMap.put(UrlID, UserName);
}
rs.close();stat.close();
return urlMap;
}
示例4: doFindAllEnabledAndNotRealTimePush
import com.mysql.jdbc.Statement; //导入依赖的package包/类
@Override
/**
*
* @Title: doFindAllEnabledAndNotRealTimePush
* @Description: 发现所有不处于激活状态同时是实时推送的Url
* @return Map<Integer, String>
* @throws SQLException
*/
public Map<Integer, String> doFindAllEnabledAndNotRealTimePush() throws SQLException {
String query = "select UrlID,UserName from Url where Enabled=true and RealTimePush=false";
Statement stat = (Statement) conn.createStatement();
ResultSet rs = stat.executeQuery(query);
Map<Integer,String> urlMap= new HashMap<Integer,String>();
while(rs.next()){
int UrlID = rs.getInt(1);
String UserName = rs.getString(2);
urlMap.put(UrlID, UserName);
}
rs.close();stat.close();
return urlMap;
}
示例5: getAllUrl
import com.mysql.jdbc.Statement; //导入依赖的package包/类
@Override
/**
*
* @Title: getAllUrl
* @Description: ����Url��������������UrlID�Ͷ�ӦUrl��
* @return Map<Integer,String>
* @throws SQLException
*/
public Map<Integer,String> getAllUrl() throws SQLException {
String query = "select UrlID,Url from Url where Enabled=true";
Statement stat = (Statement) conn.createStatement();
ResultSet rs = stat.executeQuery(query);
Map<Integer,String> urlMap= new HashMap<Integer,String>();
while(rs.next()){
int UrlID = rs.getInt(1);
String Url = rs.getString(2);
urlMap.put(UrlID, Url);
}
rs.close();stat.close();
return urlMap;
}
示例6: testIsJdbcInterface
import com.mysql.jdbc.Statement; //导入依赖的package包/类
/**
* Tests Util.isJdbcInterface()
*
* @throws Exception
*/
public void testIsJdbcInterface() throws Exception {
// Classes directly or indirectly implementing JDBC interfaces.
assertTrue(Util.isJdbcInterface(PreparedStatement.class));
assertTrue(Util.isJdbcInterface(StatementImpl.class));
assertTrue(Util.isJdbcInterface(Statement.class));
assertTrue(Util.isJdbcInterface(ResultSetImpl.class));
Statement s = (Statement) Proxy.newProxyInstance(this.getClass().getClassLoader(), new Class<?>[] { Statement.class }, new InvocationHandler() {
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
return null;
}
});
assertTrue(Util.isJdbcInterface(s.getClass()));
// Classes not implementing JDBC interfaces.
assertFalse(Util.isJdbcInterface(Util.class));
assertFalse(Util.isJdbcInterface(UtilsTest.class));
}
示例7: preProcess
import com.mysql.jdbc.Statement; //导入依赖的package包/类
public ResultSetInternalMethods preProcess(String sql, Statement interceptedStatement, Connection connection) throws SQLException {
String key = getSessionKey();
if (key != null && !key.equals(this.currentSessionKey)) {
PreparedStatement pstmt = connection.clientPrepareStatement("SET @mysql_proxy_session=?");
try {
pstmt.setString(1, key);
pstmt.execute();
} finally {
pstmt.close();
}
this.currentSessionKey = key;
}
return null;
}
示例8: populateMapWithSessionStatusValues
import com.mysql.jdbc.Statement; //导入依赖的package包/类
private void populateMapWithSessionStatusValues(Connection connection, Map<String, String> toPopulate) throws SQLException {
java.sql.Statement stmt = null;
java.sql.ResultSet rs = null;
try {
toPopulate.clear();
stmt = connection.createStatement();
rs = stmt.executeQuery("SHOW SESSION STATUS");
Util.resultSetToMap(toPopulate, rs);
} finally {
if (rs != null) {
rs.close();
}
if (stmt != null) {
stmt.close();
}
}
}
示例9: createPet
import com.mysql.jdbc.Statement; //导入依赖的package包/类
public static int createPet(int itemid) {
try {
PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("INSERT INTO pets (name, level, closeness, fullness, summoned) VALUES (?, 1, 0, 100, 0)", Statement.RETURN_GENERATED_KEYS);
ps.setString(1, MapleItemInformationProvider.getInstance().getName(itemid));
ps.executeUpdate();
ResultSet rs = ps.getGeneratedKeys();
int ret = -1;
if (rs.next()) {
ret = rs.getInt(1);
}
rs.close();
ps.close();
return ret;
} catch (SQLException e) {
return -1;
}
}
示例10: insert
import com.mysql.jdbc.Statement; //导入依赖的package包/类
public void insert(Item item) {
Connection connection = null;
try {
connection = dataSource.getConnection();
PreparedStatement statement = connection.prepareStatement(SQL_INSERT, Statement.RETURN_GENERATED_KEYS);
statement.setString(1, item.getName());
statement.setLong(2, item.getWarehouse_id());
statement.execute();
ResultSet generatedkeys = statement.getGeneratedKeys();
if (generatedkeys.next()) {
item.setId(generatedkeys.getLong(1));
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
dataSource.closeConnection(connection);
}
}
示例11: insert
import com.mysql.jdbc.Statement; //导入依赖的package包/类
public void insert(Warehouse warehouse) {
Connection connection = null;
try {
connection = dataSource.getConnection();
PreparedStatement statement = connection.prepareStatement(SQL_INSERT, Statement.RETURN_GENERATED_KEYS);
statement.setString(1, warehouse.getAddress());
statement.execute();
ResultSet generatedkeys = statement.getGeneratedKeys();
if (generatedkeys.next()) {
warehouse.setId(generatedkeys.getLong(1));
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
dataSource.closeConnection(connection);
}
}
示例12: testGetImplementedInterfaces
import com.mysql.jdbc.Statement; //导入依赖的package包/类
/**
* Tests Util.isJdbcPackage()
*
* @throws Exception
*/
public void testGetImplementedInterfaces() throws Exception {
Class<?>[] ifaces;
ifaces = Util.getImplementedInterfaces(Statement.class);
assertEquals(1, ifaces.length);
assertEquals(ifaces[0], java.sql.Statement.class);
ifaces = Util.getImplementedInterfaces(StatementImpl.class);
assertEquals(1, ifaces.length);
assertEquals(ifaces[0], Statement.class);
ifaces = Util.getImplementedInterfaces(ConnectionImpl.class);
assertEquals(3, ifaces.length);
List<Class<?>> ifacesList = Arrays.asList(ifaces);
for (Class<?> clazz : new Class<?>[] { MySQLConnection.class, Serializable.class, ConnectionProperties.class }) {
assertTrue(ifacesList.contains(clazz));
}
}
示例13: JavaSEProfileDB
import com.mysql.jdbc.Statement; //导入依赖的package包/类
public JavaSEProfileDB() {
try {
// this will load the MySQL driver, each DB has its own driver
Class.forName("com.mysql.jdbc.Driver");
// setup the connection with the DB.
connect = DriverManager
.getConnection("jdbc:mysql://localhost/feedback?"
+ "user=root&password=root");
// statements allow to issue SQL queries to the database
statement = (Statement) connect.createStatement();
} catch (Exception e) {
System.err.println("Got an exception! ");
System.err.println(e.getMessage());
}
}
开发者ID:chauhansaurabhb,项目名称:EndUserInteractioion_RequestResponse_Command,代码行数:19,代码来源:JavaSEProfileDB.java
示例14: GetConsultationStatus
import com.mysql.jdbc.Statement; //导入依赖的package包/类
/**
* Returns the db_status of a consultation from the db.
*
* @param curl - The consultation's url
* @return - The consultation's db status
* @throws java.sql.SQLException
*/
public static String GetConsultationStatus(String curl) throws SQLException {
Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery("SELECT completed FROM consultation WHERE consultation_url = '" + curl + "';");
int db_status = 0;
if (rs.next()) {
db_status = rs.getInt(1);
}
if (db_status == 2) {
return "blue";
} else if (db_status == 1) {
return "red";
} else {
return "green";
}
}
示例15: LogCrawler
import com.mysql.jdbc.Statement; //导入依赖的package包/类
/**
* Starts the crawler's activity log
*
* @param startTime - The start time of the crawling procedure
* @return - The activity's log id
* @throws java.sql.SQLException
*/
public static int LogCrawler(long startTime) throws SQLException {
String insertLogSql = "INSERT INTO log.activities (module_id, start_date, end_date, status_id, message) VALUES (?,?,?,?,?)";
PreparedStatement prepLogCrawlStatement = connection.prepareStatement(insertLogSql, Statement.RETURN_GENERATED_KEYS);
prepLogCrawlStatement.setInt(1, 1);
prepLogCrawlStatement.setTimestamp(2, new java.sql.Timestamp(startTime));
prepLogCrawlStatement.setTimestamp(3, null);
prepLogCrawlStatement.setInt(4, 1);
prepLogCrawlStatement.setString(5, null);
prepLogCrawlStatement.executeUpdate();
ResultSet rsq = prepLogCrawlStatement.getGeneratedKeys();
int crawlerId = 0;
if (rsq.next()) {
crawlerId = rsq.getInt(1);
}
prepLogCrawlStatement.close();
return crawlerId;
}