FAQ Database Discussion Community


Find all tables in a database with Java

java,mysql,database,resultset,h2
I'm trying to get all the table names in my database back through Java but I am having problems using the Result Set. The below works and I can see the info listed when I inspect the result set. How do i get the table names from the result set...

Do I need next() for a ResultSet with one row?

java,mysql,jdbc,resultset
I have the following code Statement stmt = SqlHelper.initializeDB(); String query = "SELECT status " + "FROM books " + "WHERE bookId = '" + bookId + "'"; ResultSet rs = stmt.executeQuery(query); result = rs.getString(1); rs.close(); SqlHelper.closeConnection(); Do I need to use rs.next()? I am sure there is only going...

Display tables of a database in java

java,mysql,swing,awt,resultset
I'm working on a java application, and I want to display the list of the tables in a Mysql database, I searched on the net and I found that "SHOW TABLES FROM [DB]" is the appropriate request, but how can I dispaly the result of this last on a java...

How to select multiple row in postgresql?

sql,postgresql,select,resultset
I can give a result set consisting of a single value, say 1, as follows: SELECT 1 as column; and it gives me the result set: column ------ 1 But I have a list of such values represented as a string (1, 4, 7, ...) and I need to produce...

Freebase Search API - Get All Results

java,google-api,resultset,freebase
Is it possible now to get all results from Freebase Search API? Today I was trying 2 approaches in Java: 1) www.googleapis.com/freebase/v1/search?filter=..." Using "cursor"(integer) and "limit" options. 2) www.freebase.com/ajax/156b.lib.www.tags.svn.freebase-site.googlecode.dev/cuecard/mqlread.ajax?&query= Try to simulate 'Query Editor' (https://www.freebase.com/query) Using "cursor" from the previous results set (String). But in both of these approaches I...

SSIS take oracle variable and use them in a ssis resulset

sql-server,oracle,ssis,resultset
Hi I have an execute sql task in one of my ssis package. I need to check if some of my tables have values inside them and store the result in a variable.I then need to use those variables later on in my package. My question is how do I...

Checking for duplicates with ResultSet.getString

java,sql,jsp,resultset,duplicate-data
May I know the best way to validate a variable by checking if there are any duplicates in my database? I've tried several different ways already, but whenever the first if condition is not fulfilled, a blank page would be shown Edit: I've thought about setting username to a unique...

AsyncTask and ResultSet on android

android,android-asynctask,resultset
I have a problem when I use the AsyncTask, this code works fine, but when I return a ResultSet, in the mainActivity i haven't the result of the AsyncTask, and my app break. I try using a timer and a Thread.sleep and don't work blast_dbConnect task = new blast_dbConnect("asd","123",MainActivity.this); task.execute("Conectando",sql);...

Best Approach to get `ResultSet` size

java,jdbc,resultset
What's the best approach (Speed) to get RestultSet size in Java, so I can store them in Array, which I need to specify it's size before creation, I've found the following: Call ResultSet.last(), then call ResultSet.getRow(). Iterate through ResultSet using next() while having a counter. Execute a SELECT COUNT query...

ResultSet#next() is returning false even though my query is correct

java,jsp,jdbc,resultset
I have written the following code in an jsp file.. basically what it dose is that it checks whether there is any data with the particular bank name, card number and password..to check this i have used a select query.. the query is correct but the result set is returning...

Using a ResultSet after executing two different queries with statement.executeQuery() [duplicate]

java,jdbc,resultset
This question already has an answer here: Invalid state, the ResultSet object is closed 1 answer Given the code below: //connection stuff ResultSet rs = statement.executeQuery(query1); statement.executeQuery(query2); while(rs.next){ //code } Is the result set rs still valid even though a second statement has been executed? I know that when...

Java resultset displayed in reverse order

java,fetch,reverse,resultset
I'm testing a very simple Java webapp doGet() method with the following code: protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try { Class.forName("oracle.jdbc.OracleDriver"); } catch(ClassNotFoundException ex) { System.out.println(ex); } String sql_qrp="select * from HR.EMP_MGMT"; try { Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521/XE","HR","HR"); try(Statement stm=con.createStatement()) { ResultSet rs=stm.executeQuery(sql_qrp);...

Alternative to ResultSet for storing data from database

java,sql,jdbc,prepared-statement,resultset
I have a database and at present I am using the PreparedStatement to call data from the database using an SQL statement. However I know that once a PreparedStatement has finished the ResultSet closes. I need an alternative to this (the resultset closing) as the Prepared Statement is run every...

Jackson putting quotes around numeric values from OracleResultSet

java,json,oracle,jackson,resultset
I'm using the Jackson JSON API to create JSON objects in Java and then print. My code is similar to: OracleResultSet rs = getMyResultSet(); OracleResultSetMetaData rsmd = (OracleResultSetMetaData)rs.getMetaData(); int columnCount = rsmd.getColumnCount(); String[] columnNames = new String[columnCount]; int[] columntypes = new int[columnCount]; for(int i = 1; i < columnCount; ++i)...

ResultSet- What kind of object is it?

java,jdbc,arraylist,resultset,memory-address
I'm iterating over a ResultSet and save it to a ArrayList. weatherData = Arrays.asList ( new WeatherInfo(rs.getDate(1), rs.getInt(2)... When I do a System.out.println(weatherData); I see this in the Eclipse Console: [[email protected], [email protected] What does it mean? Is it a value I can handle in Java or not? Is this the...

Need to convert a Result Set to some data structure

java,sql,tree,resultset
I have a java.sql.ResultSet like this: ============================= | colA | ColB | ColC | ColD | ============================= | 1 | 1 | 1 | 1 | | 1 | 1 | 1 | 2 | | 1 | 1 | 2 | 3 | | 1 | 1 | 2...

How to get all trigger names from a database using Java JDBC?

java,jdbc,resultset,sql-server-triggers,database-metadata
I'd like to retrieve all trigger names from an oracle database schema. I use getFunctions to retrieve all functions but i can't find another one for the triggers. DatabaseMetaData dbmd; ResultSet result = dbmd.getFunctions(null, Ousername, null); ...

Method to get only procedures from an oracle database using Java

java,resultset,procedure,database-metadata
I need to get only the procedures using java DatabaseMetaData but this method returns also the functions' names. DatabaseMetaData dbmd=con.getMetaData(); ResultSet result = dbmd.getProcedures(null, Ousername, null); ...

How to use ResultSet: absolute(int row) in java and dispaly retrieved rows in tabular format through jsp using jstl

java,jsp,cursor,resultset
I want to retrieve some specific rows from ResultSet by using absolute(int row) method.I have retrieved all the rows in tabular format by following code: public String[][] reference() { String a[][]=new String[46][2]; int i=0; try { con = getConnection(); stmt = con.createStatement(rs.TYPE_SCROLL_SENSITIVE,rs.CONCUR_READ_ONLY); String sql="select logtime,beam_current from INDUS2_BDS.dbo.DCCT where logtime between...

How to get all type names from a database using Java Swing? [duplicate]

java,oracle,resultset,database-metadata,sql-types
This question already has an answer here: How to get all trigger names from a database using Java JDBC? 1 answer I'd like to retrieve all trigger names from an oracle database schema. I use getFunctions to retrieve all functions but i can't find another one for the types....

foreach on resultset mysql return only one value randomic

php,mysql,sql,foreach,resultset
I am trying do some simple select in one script. I see if I try to read my resultset with a while there isn't any problem but if I try to use foreach, I just read 1 o 2 value all wrong... why? $sql = " select * from tutorials_tbl";...

How to use CachedRowSet in Google App Engine?

java,google-app-engine,jdbc,resultset,google-cloud-endpoints
I am using Google App Engine (Endpoints) to generate a simple API service. I'm currently trying to make my queries to the database faster and more efficient, so I decided to double check where I was calling ResultSet and Connections and closing them. However I want to use CachedRowSet and...

How to add boolean column into resultset in java then add result to jtable

java,jtable,resultset
let me explain what i trying to achieve here in my result set their are data with 4 columns then i need to add 1 more column manually and it's should contain boolean values (false) ResultSet res = DbConnect.tabelDb(sql); // get result set List expRptColWise = new ArrayList(); for (int...

Select every record in SQL

sql,sql-server,database,table,resultset
Is there any easy way to select every record for two tables, kind of hard to explain but if I have two tables Client and Product Client A B C Product 1 2 3 What query would get a result like this: RESULT A1 A2 A3 B1 B2 B3 C1...

SQLException: the result set is closed

java,sql,jdbc,resultset
I am a beginner in Java using NetBeans and I was trying to create something similar to a faculty registration system. I use SQL Server 2005 to create the DB. During the implementation I was trying to create a function to make students able to register their subjects so the...

MySQL fetch array not collecting and returning all the rows | PHP | MySQL

php,mysql,function,select,resultset
I have a function (see below) public function ReadBets_Open($id) { $queryBase = "SELECT * FROM `vr_wp_bets` WHERE `is_open` = 'true' AND `id` = '%s';"; $queryBase2 = sprintf($queryBase, $id); $selectQuery = mysql_query($queryBase2); $return = "<div style='max-height: 400px; overflow: scroll;'>"; while ($result = mysql_fetch_array($selectQuery)) { //var_dump($result); $return = "<div style='border: 1pt solid...

Multipe Queries and ResultSets stored in one ArrayList

java,arraylist,while-loop,resultset
I'm trying to store multiple ResultSets into one ArrayList. I'm catching an error on my while-loop at the first ResultSet. Here's my code: List<String> target= new ArrayList<String>(); try{ wpCall.Connect("database"); wpCall.ResetParms(); sql = "SELECT column"; sql += "FROM table"; sql += "WHERE col2= 'val1'"; sql += "AND col3= 'field2'"; ResultSet rst1...

How to retrieve all the values from LinkedHashMap in java while using ResulSet.absolute() method

java,resultset,linkedhashmap
I have to retrieve only some specific rows from the ResultSet ,for that I have absolute() method of ResultSet and have put the values of that row in a LinkedHashMap. But when I execute the code ,only last row is being printed not all the specified rows. The code is:...

Getting a Result Set's Column Names via T-SQL

tsql,resultset
Is there a way to get the column names that an arbitrary query will return using just T-SQL that works with pre-2012 versions of Microsoft SQL Server? What Doesn't Work: sys.columns and INFORMATION_SCHEMA.COLUMNS work great for obtaining the column list for tables or views but don't work with arbitrary queries....

Testing two result.next()

java,database,oracle,jdbc,resultset
I would need help to know why one of my prepared statement are not executed. here is the code : The prepared statement : updaterBalance = connection.prepareStatement("UPDATE accounts SET balance = ? WHERE account_id = ?") The table : statmnt.executeUpdate("CREATE TABLE accounts ( account_id INTEGER, balance DOUBLE PRECISION)"); statmnt.executeUpdate("ALTER TABLE...

A better way to store unknown number of attributes

sql,postgresql,resultset
Currently using Postgres 9.3 I have a Table Person(Id, FName, Lname, Address1, Adress2, phone1, phone1,....) I could do Person(id, FName, Lname) and then Address(PersonID, AddressName, Address) and Pone(PersonID, PhoneName, Number) But when when I need to add a new attribute, say email, I need to change the schema and add...

Using ResultSetMetaData with same column name in 2 tables [duplicate]

java,sql,database,sybase,resultset
This question already has an answer here: JDBC ResultSet get columns with table alias 6 answers I want to get column names from 2 tables and then their value using ResultSetMetaData and ResultSet. Let's say table myTable has columns x, y and z. I do Select * from table...