本文整理了Java中io.vertx.ext.sql.ResultSet.getColumnNames
方法的一些代码示例,展示了ResultSet.getColumnNames
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ResultSet.getColumnNames
方法的具体详情如下:
包路径:io.vertx.ext.sql.ResultSet
类名称:ResultSet
方法名:getColumnNames
[英]Get the column names
[中]获取列名
代码示例来源:origin: apiman/apiman
/**
* @see io.apiman.gateway.engine.components.jdbc.IJdbcResultSet#getColumnNames()
*/
@Override
public List<String> getColumnNames() {
return resultSet.getColumnNames();
}
代码示例来源:origin: io.vertx/vertx-sql-common
public static void toJson(ResultSet obj, java.util.Map<String, Object> json) {
if (obj.getColumnNames() != null) {
JsonArray array = new JsonArray();
obj.getColumnNames().forEach(item -> array.add(item));
json.put("columnNames", array);
}
if (obj.getNext() != null) {
json.put("next", obj.getNext().toJson());
}
json.put("numColumns", obj.getNumColumns());
json.put("numRows", obj.getNumRows());
if (obj.getOutput() != null) {
json.put("output", obj.getOutput());
}
if (obj.getResults() != null) {
JsonArray array = new JsonArray();
obj.getResults().forEach(item -> array.add(item));
json.put("results", array);
}
if (obj.getRows() != null) {
JsonArray array = new JsonArray();
obj.getRows().forEach(item -> array.add(item));
json.put("rows", array);
}
}
}
代码示例来源:origin: io.vertx/vertx-mysql-postgresql-client-jasync
@Test
public void testSimpleSelect(TestContext context) {
Async async = context.async();
client.getConnection(ar -> {
if (ar.failed()) {
context.fail(ar.cause());
return;
}
// Create table
conn = ar.result();
setupSimpleTable(conn, ar2 -> conn.queryWithParams("SELECT name FROM test_table WHERE id=?",
new JsonArray().add(2), ar3 -> {
if (ar3.failed()) {
context.fail(ar3.cause());
} else {
final ResultSet res = ar3.result();
context.assertNotNull(res);
context.assertEquals(res.getColumnNames().size(), 1);
context.assertEquals(res.getColumnNames().get(0), "name");
context.assertEquals(Data.NAMES.get(2), res.getResults().get(0).getString(0));
async.complete();
}
}));
});
}
代码示例来源:origin: vert-x3/vertx-mysql-postgresql-client
@Test
public void testSimpleSelect(TestContext context) {
Async async = context.async();
client.getConnection(ar -> {
if (ar.failed()) {
context.fail(ar.cause());
return;
}
// Create table
conn = ar.result();
setupSimpleTable(conn, ar2 -> conn.queryWithParams("SELECT name FROM test_table WHERE id=?",
new JsonArray().add(2), ar3 -> {
if (ar3.failed()) {
context.fail(ar3.cause());
} else {
final ResultSet res = ar3.result();
context.assertNotNull(res);
context.assertEquals(res.getColumnNames().size(), 1);
context.assertEquals(res.getColumnNames().get(0), "name");
context.assertEquals(Data.NAMES.get(2), res.getResults().get(0).getString(0));
async.complete();
}
}));
});
}
代码示例来源:origin: vert-x3/vertx-mysql-postgresql-client
@Test
public void testSimpleSelect(TestContext context) {
Async async = context.async();
client.getConnection(ar -> {
if (ar.failed()) {
context.fail(ar.cause());
return;
}
// Create table
conn = ar.result();
setupSimpleTable(conn, ar2 -> conn.queryWithParams("SELECT name FROM test_table WHERE id=?",
new JsonArray().add(2), ar3 -> {
if (ar3.failed()) {
context.fail(ar3.cause());
} else {
final ResultSet res = ar3.result();
context.assertNotNull(res);
context.assertEquals(res.getColumnNames().size(), 1);
context.assertEquals(res.getColumnNames().get(0), "name");
context.assertEquals(Data.NAMES.get(2), res.getResults().get(0).getString(0));
async.complete();
}
}));
});
}
代码示例来源:origin: io.vertx/vertx-jdbc-service
@Test
public void testSelectWithParameters() {
String sql = "SELECT ID, FNAME, LNAME FROM select_table WHERE fname = ?";
connection().queryWithParams(sql, new JsonArray().add("john"), onSuccess(resultSet -> {
assertNotNull(resultSet);
assertEquals(1, resultSet.getResults().size());
assertEquals("ID", resultSet.getColumnNames().get(0));
assertEquals("FNAME", resultSet.getColumnNames().get(1));
assertEquals("LNAME", resultSet.getColumnNames().get(2));
JsonArray result0 = resultSet.getResults().get(0);
assertEquals(1, (int) result0.getInteger(0));
assertEquals("john", result0.getString(1));
assertEquals("doe", result0.getString(2));
testComplete();
}));
await();
}
代码示例来源:origin: io.vertx/vertx-jdbc-client
@Test
public void testSelectWithParameters() {
String sql = "SELECT ID, FNAME, LNAME FROM select_table WHERE fname = ?";
connection().queryWithParams(sql, new JsonArray().add("john"), onSuccess(resultSet -> {
assertNotNull(resultSet);
assertEquals(1, resultSet.getResults().size());
assertEquals("ID", resultSet.getColumnNames().get(0));
assertEquals("FNAME", resultSet.getColumnNames().get(1));
assertEquals("LNAME", resultSet.getColumnNames().get(2));
JsonArray result0 = resultSet.getResults().get(0);
assertEquals(1, (int) result0.getInteger(0));
assertEquals("john", result0.getString(1));
assertEquals("doe", result0.getString(2));
testComplete();
}));
await();
}
代码示例来源:origin: io.vertx/vertx-jdbc-client
@Test
public void testSelectWithLabels() {
String sql = "SELECT ID as \"IdLabel\", FNAME as \"first_name\", LNAME as \"LAST.NAME\" FROM select_table WHERE fname = ?";
connection().queryWithParams(sql, new JsonArray().add("john"), onSuccess(resultSet -> {
assertNotNull(resultSet);
assertEquals(1, resultSet.getResults().size());
assertEquals("IdLabel", resultSet.getColumnNames().get(0));
assertEquals("first_name", resultSet.getColumnNames().get(1));
assertEquals("LAST.NAME", resultSet.getColumnNames().get(2));
JsonArray result0 = resultSet.getResults().get(0);
assertEquals(1, (int) result0.getInteger(0));
assertEquals("john", result0.getString(1));
assertEquals("doe", result0.getString(2));
JsonObject row0 = resultSet.getRows().get(0);
assertEquals(1, (int) row0.getInteger("IdLabel"));
assertEquals("john", row0.getString("first_name"));
assertEquals("doe", row0.getString("LAST.NAME"));
testComplete();
}));
await();
}
代码示例来源:origin: io.vertx/vertx-sql-common
@Test
public void testResultSet() {
assertEquals(numRows, rs.getNumRows());
assertEquals(columnNames.size(), rs.getNumColumns());
assertEquals(columnNames.size(), rs.getColumnNames().size());
assertEquals(columnNames, rs.getColumnNames());
assertEquals(results, rs.getResults());
List<JsonObject> rows = rs.getRows();
assertEquals(numRows, rs.getRows().size());
int index = 0;
for (JsonObject row: rows) {
JsonArray result = results.get(index);
assertEquals(columnNames.size(), row.size());
assertEquals(row.size(), result.size());
for (int i = 0; i < columnNames.size(); i++) {
String columnName = columnNames.get(i);
String columnValue = result.getString(i);
assertEquals(columnValue, row.getString(columnName));
}
index++;
}
}
代码示例来源:origin: io.vertx/vertx-mysql-postgresql-client-jasync
@Test
public void testUsingUUIDsInTables(TestContext context) {
Async async = context.async();
final UUID uuid = UUID.randomUUID();
final String name = "xyz";
client.getConnection(ar -> {
ensureSuccess(context, ar);
conn = ar.result();
setupTableWithUUIDs(conn, ar2 -> {
ensureSuccess(context, ar2);
conn.queryWithParams("INSERT INTO test_table (some_uuid, name) VALUES (?, ?)", new JsonArray().add(uuid.toString()).add(name), ar3 -> {
ensureSuccess(context, ar3);
conn.queryWithParams("SELECT some_uuid FROM test_table WHERE name = ?", new JsonArray().add(name), ar4 -> {
ensureSuccess(context, ar4);
ResultSet resultSet = ar4.result();
context.assertEquals(1, resultSet.getNumRows());
context.assertEquals("some_uuid", resultSet.getColumnNames().get(0));
context.assertEquals(new JsonObject().put("some_uuid", uuid.toString()), resultSet.getRows().get(0));
async.complete();
});
});
});
});
}
代码示例来源:origin: vert-x3/vertx-mysql-postgresql-client
@Test
public void testUsingUUIDsInTables(TestContext context) {
Async async = context.async();
final UUID uuid = UUID.randomUUID();
final String name = "xyz";
client.getConnection(ar -> {
ensureSuccess(context, ar);
conn = ar.result();
setupTableWithUUIDs(conn, ar2 -> {
ensureSuccess(context, ar2);
conn.queryWithParams("INSERT INTO test_table (some_uuid, name) VALUES (?, ?)", new JsonArray().add(uuid.toString()).add(name), ar3 -> {
ensureSuccess(context, ar3);
conn.queryWithParams("SELECT some_uuid FROM test_table WHERE name = ?", new JsonArray().add(name), ar4 -> {
ensureSuccess(context, ar4);
ResultSet resultSet = ar4.result();
context.assertEquals(1, resultSet.getNumRows());
context.assertEquals("some_uuid", resultSet.getColumnNames().get(0));
context.assertEquals(new JsonObject().put("some_uuid", uuid.toString()), resultSet.getRows().get(0));
async.complete();
});
});
});
});
}
代码示例来源:origin: vert-x3/vertx-mysql-postgresql-client
@Test
public void testUsingUUIDsInTables(TestContext context) {
Async async = context.async();
final UUID uuid = UUID.randomUUID();
final String name = "xyz";
client.getConnection(ar -> {
ensureSuccess(context, ar);
conn = ar.result();
setupTableWithUUIDs(conn, ar2 -> {
ensureSuccess(context, ar2);
conn.queryWithParams("INSERT INTO test_table (some_uuid, name) VALUES (?, ?)", new JsonArray().add(uuid.toString()).add(name), ar3 -> {
ensureSuccess(context, ar3);
conn.queryWithParams("SELECT some_uuid FROM test_table WHERE name = ?", new JsonArray().add(name), ar4 -> {
ensureSuccess(context, ar4);
ResultSet resultSet = ar4.result();
context.assertEquals(1, resultSet.getNumRows());
context.assertEquals("some_uuid", resultSet.getColumnNames().get(0));
context.assertEquals(new JsonObject().put("some_uuid", uuid.toString()), resultSet.getRows().get(0));
async.complete();
});
});
});
});
}
代码示例来源:origin: io.vertx/vertx-jdbc-service
@Test
public void testSelectWithLabels() {
String sql = "SELECT ID as \"IdLabel\", FNAME as \"first_name\", LNAME as \"LAST.NAME\" FROM select_table WHERE fname = ?";
connection().queryWithParams(sql, new JsonArray().add("john"), onSuccess(resultSet -> {
assertNotNull(resultSet);
assertEquals(1, resultSet.getResults().size());
assertEquals("IdLabel", resultSet.getColumnNames().get(0));
assertEquals("first_name", resultSet.getColumnNames().get(1));
assertEquals("LAST.NAME", resultSet.getColumnNames().get(2));
JsonArray result0 = resultSet.getResults().get(0);
assertEquals(1, (int) result0.getInteger(0));
assertEquals("john", result0.getString(1));
assertEquals("doe", result0.getString(2));
JsonObject row0 = resultSet.getRows().get(0);
assertEquals(1, (int) row0.getInteger("IdLabel"));
assertEquals("john", row0.getString("first_name"));
assertEquals("doe", row0.getString("LAST.NAME"));
testComplete();
}));
await();
}
代码示例来源:origin: io.vertx/vertx-jdbc-client
@Test
public void testSelectOneShot() {
String sql = "SELECT ID, FNAME, LNAME FROM select_table ORDER BY ID";
client.query(sql, query -> {
assertFalse(query.failed());
final ResultSet resultSet = query.result();
assertNotNull(resultSet);
assertEquals(2, resultSet.getResults().size());
assertEquals("ID", resultSet.getColumnNames().get(0));
assertEquals("FNAME", resultSet.getColumnNames().get(1));
assertEquals("LNAME", resultSet.getColumnNames().get(2));
JsonArray result0 = resultSet.getResults().get(0);
assertEquals(1, (int) result0.getInteger(0));
assertEquals("john", result0.getString(1));
assertEquals("doe", result0.getString(2));
JsonArray result1 = resultSet.getResults().get(1);
assertEquals(2, (int) result1.getInteger(0));
assertEquals("jane", result1.getString(1));
assertEquals("doe", result1.getString(2));
testComplete();
});
await();
}
代码示例来源:origin: io.vertx/vertx-mysql-postgresql-client-jasync
@Test
public void someTest(TestContext context) throws Exception {
Async async = context.async();
client.getConnection(connAr -> {
ensureSuccess(context, connAr);
conn = connAr.result();
conn.query("SELECT 1 AS something", resultSetAr -> {
ensureSuccess(context, resultSetAr);
ResultSet resultSet = resultSetAr.result();
context.assertNotNull(resultSet);
context.assertNotNull(resultSet.getColumnNames());
context.assertNotNull(resultSet.getResults());
context.assertEquals(new JsonArray().add(1), resultSet.getResults().get(0));
async.complete();
});
});
}
代码示例来源:origin: io.vertx/vertx-jdbc-client
@Test
public void testSelect() {
String sql = "SELECT ID, FNAME, LNAME FROM select_table ORDER BY ID";
connection().query(sql, onSuccess(resultSet -> {
assertNotNull(resultSet);
assertEquals(2, resultSet.getResults().size());
assertEquals("ID", resultSet.getColumnNames().get(0));
assertEquals("FNAME", resultSet.getColumnNames().get(1));
assertEquals("LNAME", resultSet.getColumnNames().get(2));
JsonArray result0 = resultSet.getResults().get(0);
assertEquals(1, (int) result0.getInteger(0));
assertEquals("john", result0.getString(1));
assertEquals("doe", result0.getString(2));
JsonArray result1 = resultSet.getResults().get(1);
assertEquals(2, (int) result1.getInteger(0));
assertEquals("jane", result1.getString(1));
assertEquals("doe", result1.getString(2));
testComplete();
}));
await();
}
代码示例来源:origin: vert-x3/vertx-mysql-postgresql-client
@Test
public void someTest(TestContext context) throws Exception {
Async async = context.async();
client.getConnection(connAr -> {
ensureSuccess(context, connAr);
conn = connAr.result();
conn.query("SELECT 1 AS something", resultSetAr -> {
ensureSuccess(context, resultSetAr);
ResultSet resultSet = resultSetAr.result();
context.assertNotNull(resultSet);
context.assertNotNull(resultSet.getColumnNames());
context.assertNotNull(resultSet.getResults());
context.assertEquals(new JsonArray().add(1), resultSet.getResults().get(0));
async.complete();
});
});
}
代码示例来源:origin: io.vertx/vertx-jdbc-service
@Test
public void testSelect() {
String sql = "SELECT ID, FNAME, LNAME FROM select_table ORDER BY ID";
connection().query(sql, onSuccess(resultSet -> {
assertNotNull(resultSet);
assertEquals(2, resultSet.getResults().size());
assertEquals("ID", resultSet.getColumnNames().get(0));
assertEquals("FNAME", resultSet.getColumnNames().get(1));
assertEquals("LNAME", resultSet.getColumnNames().get(2));
JsonArray result0 = resultSet.getResults().get(0);
assertEquals(1, (int)result0.getInteger(0));
assertEquals("john", result0.getString(1));
assertEquals("doe", result0.getString(2));
JsonArray result1 = resultSet.getResults().get(1);
assertEquals(2, (int)result1.getInteger(0));
assertEquals("jane", result1.getString(1));
assertEquals("doe", result1.getString(2));
testComplete();
}));
await();
}
代码示例来源:origin: vert-x3/vertx-mysql-postgresql-client
@Test
public void someTest(TestContext context) throws Exception {
Async async = context.async();
client.getConnection(connAr -> {
ensureSuccess(context, connAr);
conn = connAr.result();
conn.query("SELECT 1 AS something", resultSetAr -> {
ensureSuccess(context, resultSetAr);
ResultSet resultSet = resultSetAr.result();
context.assertNotNull(resultSet);
context.assertNotNull(resultSet.getColumnNames());
context.assertNotNull(resultSet.getResults());
context.assertEquals(new JsonArray().add(1), resultSet.getResults().get(0));
async.complete();
});
});
}
代码示例来源:origin: io.vertx/vertx-mysql-postgresql-client-jasync
@Test
public void testSelectionOfNullValues(TestContext context) {
Async async = context.async();
client.getConnection(ar -> {
ensureSuccess(context, ar);
conn = ar.result();
conn.execute("DROP TABLE IF EXISTS test_nulls_table", ar2 -> {
ensureSuccess(context, ar2);
conn.execute("CREATE TABLE test_nulls_table (id BIGINT, name VARCHAR(255) NULL)",
ar3 -> {
ensureSuccess(context, ar3);
conn.execute("INSERT INTO test_nulls_table (id, name) VALUES (1, NULL)", ar4 -> {
ensureSuccess(context, ar4);
conn.query("SELECT id, name FROM test_nulls_table ORDER BY id", ar5 -> {
ensureSuccess(context, ar5);
ResultSet rs = ar5.result();
List<String> columns = rs.getColumnNames();
context.assertEquals(2, columns.size());
context.assertEquals(columns.get(0), "id");
context.assertEquals(columns.get(1), "name");
context.assertEquals(rs.getResults().size(), 1);
context.assertEquals(rs.getResults().get(0).getInteger(0), 1);
context.assertEquals(rs.getResults().get(0).getString(1), null);
async.complete();
});
});
});
});
});
}
内容来源于网络,如有侵权,请联系作者删除!