本文整理匯總了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;
}