本文整理汇总了Java中com.almworks.sqlite4java.SQLiteStatement.hasRow方法的典型用法代码示例。如果您正苦于以下问题:Java SQLiteStatement.hasRow方法的具体用法?Java SQLiteStatement.hasRow怎么用?Java SQLiteStatement.hasRow使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.almworks.sqlite4java.SQLiteStatement
的用法示例。
在下文中一共展示了SQLiteStatement.hasRow方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildSQLiteCursor
import com.almworks.sqlite4java.SQLiteStatement; //导入方法依赖的package包/类
public static SQLiteCursor buildSQLiteCursor(SQLiteConnection conn, String sql, Object[] bindArgs)
throws SQLiteException {
SQLiteStatement stmt = null;
try {
stmt = bindArguments(conn.prepare(sql), bindArgs);
List<String> columnNames = null;
List<Tuple> resultSet = new ArrayList<Tuple>();
while (!stmt.hasStepped() || stmt.hasRow()) {
if (!stmt.step()) {
break;
}
if (columnNames == null) {
columnNames = getColumnNames(stmt);
}
Tuple t = getDataRow(stmt);
logger.finest("Tuple: "+ t.toString());
resultSet.add(t);
}
return new SQLiteCursor(columnNames, resultSet);
} finally {
SQLiteWrapperUtils.disposeQuietly(stmt);
}
}
示例2: getServerFromDB
import com.almworks.sqlite4java.SQLiteStatement; //导入方法依赖的package包/类
/**
* Searches the database for a server matching the ip address and gameport to find the
* associated queryport.
*
* @param ip the ip address of the server
* @param gameport the gameport of the server
* @return returns the {@link ChivServer}; or null if not found
* @see SQLiteConnection
* @see SQLiteStatement
* @see SQLiteException
*/
public ChivServer getServerFromDB(String ip, String gameport) {
String queryport = "";
SQLiteConnection db = new SQLiteConnection(new File("browserdb"));
try {
db.open(true);
SQLiteStatement st = db.prepare("CREATE TABLE IF NOT EXISTS servers" +
"(" +
"id INTEGER PRIMARY KEY AUTOINCREMENT," +
"ip varchar(255) not null default ''," +
"queryport varchar(255) not null default ''," +
"gameport varchar(255) not null default ''" +
")");
try {
st.step();
} finally {
st.dispose();
}
st = db.prepare("SELECT queryport FROM servers WHERE ip = '" + ip + "' AND gameport = '" + gameport + "'");
try {
st.step();
if ( st.hasRow() ) {
queryport = st.columnString(0);
}
} finally {
st.dispose();
}
} catch (SQLiteException e) {
e.printStackTrace();
}
db.dispose();
if ( !queryport.equals("") ) {
return ChivServer.createChivServer(mw, ip, Integer.parseInt(queryport));
}
return null;
}
示例3: addFavorite
import com.almworks.sqlite4java.SQLiteStatement; //导入方法依赖的package包/类
/**
* Adds a {@link ChivServer} as a favorite server to the database.
*
* @param cs the {@link ChivServer} to add
* @see SQLiteConnection
* @see SQLiteStatement
* @see SQLiteException
*/
public void addFavorite(ChivServer cs) {
printlnMC("Adding server to favorites...");
SQLiteConnection db = new SQLiteConnection(new File("browserdb"));
try {
db.open(true);
SQLiteStatement st = db.prepare("CREATE TABLE IF NOT EXISTS favorite_servers" +
"(" +
"id INTEGER PRIMARY KEY AUTOINCREMENT," +
"name varchar(255) not null default ''," +
"ip varchar(255) not null default ''," +
"port varchar(255) not null default '' )");
try {
st.step();
} finally {
st.dispose();
}
//check if exists
int id = -1;
st = db.prepare("SELECT id FROM favorite_servers WHERE ip = '" + cs.mIP + "' AND port = '" + cs.mQueryPort + "'");
try {
st.step();
if ( st.hasRow() ) {
id = st.columnInt(0);
}
} finally {
st.dispose();
}
if ( id > -1 ) {
printlnMC("Server already a favorite.");
st = db.prepare("INSERT OR REPLACE INTO favorite_servers (id, name, ip, port) " +
"VALUES ( " + id + ",'" + cs.mName + "', '" + cs.mIP + "', '" + cs.mQueryPort + "' )");
try {
st.step();
} finally {
st.dispose();
}
} else {
st = db.prepare("INSERT INTO favorite_servers (name, ip, port) " +
"VALUES ('" + cs.mName + "', '" + cs.mIP + "', '" + cs.mQueryPort + "' )");
try {
st.step();
} finally {
st.dispose();
}
printlnMC("Added to favorites: " + cs.mName);
}
} catch (SQLiteException e) {
e.printStackTrace();
}
db.dispose();
}
示例4: removeFavorite
import com.almworks.sqlite4java.SQLiteStatement; //导入方法依赖的package包/类
/**
* Removes a {@link ChivServer} from the favorites database.
*
* @param cs the {@link ChivServer} to remove
* @return if the server was successfully found and removed
* @see SQLiteConnection
* @see SQLiteStatement
* @see SQLiteException
*/
public boolean removeFavorite(ChivServer cs) {
boolean removed = false;
System.out.println("Removing from favorites...");
printlnMC("Removing server from favorites...");
SQLiteConnection db = new SQLiteConnection(new File("browserdb"));
try {
db.open(true);
SQLiteStatement st = db.prepare("CREATE TABLE IF NOT EXISTS favorite_servers" +
"(" +
"id INTEGER PRIMARY KEY AUTOINCREMENT," +
"name varchar(255) not null default ''," +
"ip varchar(255) not null default ''," +
"port varchar(255) not null default '' )");
try {
st.step();
} finally {
st.dispose();
}
//check if exists
int id = -1;
st = db.prepare("SELECT id FROM favorite_servers WHERE ip = '" + cs.mIP + "' AND port = '" + cs.mQueryPort + "'");
try {
st.step();
if ( st.hasRow() ) {
id = st.columnInt(0);
}
} finally {
st.dispose();
}
if ( id > -1 ) {
st = db.prepare("DELETE FROM favorite_servers WHERE id = " + id);
try {
st.step();
for ( int i=0; i<serversFav.size(); i++ ) {
ChivServer c = serversFav.get(i);
if ( cs.mIP.equals(c.mIP) && cs.mQueryPort.equals(c.mQueryPort) ) {
serversFav.remove(i);
break;
}
}
printlnMC("Removed favorite: " + cs.mName);
removed = true;
} finally {
st.dispose();
}
} else {
printlnMC("Didn't find server in database. This is probably a bad thing.");
}
} catch (SQLiteException e) {
e.printStackTrace();
}
db.dispose();
return removed;
}
示例5: addServerToHistory
import com.almworks.sqlite4java.SQLiteStatement; //导入方法依赖的package包/类
/**
* Adds a {@link ChivServer} to the server history database. This is typically called
* when the user joins a server.
*
* @param cs the {@link ChivServer} to add
* @see SQLiteConnection
* @see SQLiteStatement
* @see SQLiteException
*/
public void addServerToHistory(ChivServer cs) {
System.out.println("Adding server to history list.");
SQLiteConnection db = new SQLiteConnection(new File("browserdb"));
try {
db.open(true);
SQLiteStatement st = db.prepare("CREATE TABLE IF NOT EXISTS server_history" +
"(" +
"id INTEGER PRIMARY KEY AUTOINCREMENT," +
"name varchar(255) not null default ''," +
"ip varchar(255) not null default ''," +
"port varchar(255) not null default '' )");
try {
st.step();
} finally {
st.dispose();
}
//check if exists
int id = -1;
st = db.prepare("SELECT id FROM server_history WHERE ip = '" + cs.mIP + "' AND port = '" + cs.mQueryPort + "'");
try {
st.step();
if ( st.hasRow() ) {
id = st.columnInt(0);
}
} finally {
st.dispose();
}
if ( id > -1 ) {
st = db.prepare("INSERT OR REPLACE INTO server_history (id, name, ip, port) " +
"VALUES ( " + id + ",'" + cs.mName + "', '" + cs.mIP + "', '" + cs.mQueryPort + "' )");
try {
st.step();
} finally {
st.dispose();
}
} else {
st = db.prepare("INSERT INTO server_history (name, ip, port) " +
"VALUES ('" + cs.mName + "', '" + cs.mIP + "', '" + cs.mQueryPort + "' )");
try {
st.step();
} finally {
st.dispose();
}
}
} catch (SQLiteException e) {
e.printStackTrace();
}
db.dispose();
}
示例6: removeServerFromHistory
import com.almworks.sqlite4java.SQLiteStatement; //导入方法依赖的package包/类
/**
* Removes a {@link ChivServer} from the history database.
*
* @param cs the {@link ChivServer} to remove
* @return if the {@link ChivServer} was successfully found and removed
* @see SQLiteConnection
* @see SQLiteStatement
* @see SQLiteException
*/
public boolean removeServerFromHistory(ChivServer cs) {
boolean removed = false;
System.out.println("Removing from history...");
printlnMC("Removing server from history...");
SQLiteConnection db = new SQLiteConnection(new File("browserdb"));
try {
db.open(true);
SQLiteStatement st = db.prepare("CREATE TABLE IF NOT EXISTS server_history" +
"(" +
"id INTEGER PRIMARY KEY AUTOINCREMENT," +
"name varchar(255) not null default ''," +
"ip varchar(255) not null default ''," +
"port varchar(255) not null default '' )");
try {
st.step();
} finally {
st.dispose();
}
//check if exists
int id = -1;
st = db.prepare("SELECT id FROM server_history WHERE ip = '" + cs.mIP + "' AND port = '" + cs.mQueryPort + "'");
try {
st.step();
if ( st.hasRow() ) {
id = st.columnInt(0);
}
} finally {
st.dispose();
}
if ( id > -1 ) {
st = db.prepare("DELETE FROM server_history WHERE id = " + id);
try {
st.step();
for ( int i=0; i<serversFav.size(); i++ ) {
ChivServer c = serversFav.get(i);
if ( cs.mIP.equals(c.mIP) && cs.mQueryPort.equals(c.mQueryPort) ) {
serversFav.remove(i);
break;
}
}
printlnMC("Removed history: " + cs.mName);
removed = true;
} finally {
st.dispose();
}
} else {
printlnMC("Didn't find server in database. This is probably a bad thing.");
}
} catch (SQLiteException e) {
e.printStackTrace();
}
db.dispose();
return removed;
}
示例7: addServerToDatabase
import com.almworks.sqlite4java.SQLiteStatement; //导入方法依赖的package包/类
/**
* Adds a server found during a refresh to the database. If the server already exists, this does nothing.
*
* @param cs the {@link ChivServer} to add to the database
* @see SQLiteConnection
* @see SQLiteStatement
* @see SQLiteException
*/
public void addServerToDatabase(ChivServer cs) {
SQLiteConnection db = new SQLiteConnection(new File("browserdb"));
try {
db.open(true);
SQLiteStatement st = db.prepare("CREATE TABLE IF NOT EXISTS servers" +
"(" +
"id INTEGER PRIMARY KEY AUTOINCREMENT," +
"ip varchar(255) not null default ''," +
"queryport varchar(255) not null default ''," +
"gameport varchar(255) not null default ''" +
")");
try {
st.step();
} finally {
st.dispose();
}
st = db.prepare("SELECT id FROM servers WHERE ip = '" + cs.mIP + "' AND queryport = '" + cs.mQueryPort +
"' AND gameport = '" + cs.mGamePort + "'");
boolean exists = false;
try {
st.step();
if ( st.hasRow() ) {
exists = true;
}
} finally {
st.dispose();
}
if ( !exists ) {
st = db.prepare("INSERT INTO servers (ip, queryport, gameport) VALUES ( '" + cs.mIP + "', '" +
cs.mQueryPort + "', '" + cs.mGamePort + "')");
try {
st.step();
} finally {
st.dispose();
}
}
} catch (SQLiteException e) {
e.printStackTrace();
}
db.dispose();
}