As is generally understood from my previous Java questions, I do not fully know, so please treat with understanding. There is a C ++ code that reads from the postgresql
database
#include <iostream> //using namespace std; #include <stdio.h> #include "libpq-fe.h" #include <string> #include <cstdio> #include <stdlib.h> int main() { PGconn *conn; PGresult *res; int rec_count; int row; int col; FILE *stream; conn = PQconnectdb("hostaddr=192.168.143.93 port=5432 connect_timeout=10 dbname=NexentaSearch user=postgres password=postgres"); if (PQstatus(conn) == CONNECTION_BAD) { fprintf(stderr, "Connection to database failed: %s\n",PQerrorMessage(conn)); puts("No connection"); exit(0); } res = PQexec(conn, "select path from tasks order by id"); if (PQresultStatus(res) != PGRES_TUPLES_OK) { printf("We didn't get the data"); exit(0); } rec_count = PQntuples(res);
I want to execute the same query to the postgresql
database in Java and write the results to ArrayList<String>
. Please help me do it.