473,800 Members | 2,457 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ResultSet not retrieving any records

3 New Member
When I run this simple program I am not getting any data back. The program creates a database, creates a table, populates the table with some data, and then tries to read the data. However, no records are returned in the ResultSet. I verify through MySQL Query Browser that the database is created and populated. I've also been unable to retrieve records with other databases. Because I'm creating the database at the root I don't think admin privileges is the problem. I'm writing the program in NetBeans 5.5.1 (although the same problem happens in Eclipse 3.3), MySQL 5.0.26, MySQL Connector/J 5.0.7 on Ubuntu 7.04 (Fiesty Fawn).

Here's the code:
Expand|Select|Wrap|Line Numbers
  1.  public static void main(String[] args) {
  2.         // TODO code application logic here
  3.            Connection conn = null;
  4.            Statement stmt = null;
  5.            ResultSet rs = null;
  6.  
  7.            try
  8.            {
  9.                 String driverName = "com.mysql.jdbc.Driver"; 
  10.                 Class.forName(driverName).newInstance();
  11.                 String username = "root";
  12.                 String password = "password";
  13.                 String url = "jdbc:mysql://localhost:3306"; 
  14.                 conn = DriverManager.getConnection(url, username, password);
  15.  
  16.                 System.out.println("Creating database");
  17.                 PreparedStatement ps = null;
  18.                 String createDatabase = "CREATE DATABASE dbNetBeans";
  19.                 ps = conn.prepareStatement(createDatabase);
  20.                 ps.executeUpdate();
  21.  
  22.                 System.out.println("Creating table tblNetBeans");
  23.                 String createTable = "CREATE TABLE dbNetBeans.tblTest (testCol varchar(30))";
  24.                 ps = conn.prepareStatement(createTable);
  25.                 ps.executeUpdate();
  26.  
  27.                 System.out.println("Inserting data to tblTest");
  28.                 String insert = "INSERT INTO dbNetBeans.tblTest (testCol) VALUES ('Test info')";
  29.                 ps = conn.prepareStatement(insert);
  30.                 ps.executeUpdate();
  31.                 ps.executeUpdate(); //two records
  32.  
  33.                 System.out.println("Getting info from tblTest");
  34.                 stmt = conn.createStatement();
  35.                 rs = stmt.executeQuery("SELECT * FROM dbNetBeans.tblTest");
  36.                 //rs = stmt.getResultSet();  this didn't help
  37.                 System.out.println("Number of records in rs: " + rs.getFetchSize());
  38.  
  39.            }
  40.            catch (ClassNotFoundException e) 
  41.            {
  42.                 System.out.println("Could not find class");
  43.                 e.printStackTrace();
  44.             } 
  45.             catch (SQLException e) 
  46.             {
  47.                 System.out.println(e.getMessage());
  48.                 e.printStackTrace();
  49.             }
  50.            catch (Exception ex)
  51.             {
  52.                 ex.printStackTrace();
  53.             }
  54.            finally
  55.            {
  56.                try { conn.close(); stmt.close(); }
  57.                catch (Exception ignore) { }
  58.            }
  59.     }
  60.  
Here's the output:
Expand|Select|Wrap|Line Numbers
  1. init:
  2. deps-jar:
  3. Compiling 1 source file to /home/steve/DatabaseTest/build/classes
  4. compile:
  5. Creating database
  6. Creating table tblNetBeans
  7. Inserting data to tblTest
  8. Getting info from tblTest
  9. Number of records in rs: 0
  10. debug:
  11. BUILD SUCCESSFUL (total time: 3 seconds)
  12.  
Sep 29 '07 #1
2 2182
gophersounds
3 New Member
Oops - I'm running Java 1.6.
Sep 29 '07 #2
gophersounds
3 New Member
Never mind -- I misunderstood the purpose of getFetchSize. I thought it was similar to .Net's DataSet.Table.R ows.Count.
Oct 4 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
1699
by: Jonathan Beam | last post by:
I'm trying to create a wrapper procedure. The procedure I'm calling returns 2 resultsets. I really only need the second, but I'm not sure how to get the second resultset. Is there something like ADO's Resultset.NextRecordset for Transaction SQL? CREATE PROCEDURE dbo.NAMissionsSearchNameWrapper @Search varchar, @SortByName INT AS CREATE TABLE #NaMissionsSearchNameTemp(
0
1174
by: Mark Jay Johansen | last post by:
Does anyone know what the relative performance would be of using updateable result sets versus using individual insert or update statements? (Specifically at the moment I'm dealing with JSP programs using J/Connector on Tomcat, if that matters.) For example, if I want to read ten records and update them, would I be better off to use an updateable result set and update each as I go, or to issue UPDATE statements for each? (Intuitively it...
1
1399
by: Catherine | last post by:
I have several ResultSet Querys/Statements within my page. An example of the code looks like this: ResultSet rs1 = stmt1.executeQuery("SELECT right(' ' + '$' + convert(varchar,SUM(ActivePrim),1), 15) AS 'ActivePrim', right(' ' + '$' + convert(varchar,SUM(KGAP),1), 15) AS 'KGAP', right(' ' + '$' + convert(varchar,SUM(PrimaryRepo),1), 15) AS 'PrimaryRepo', right(' ' + '$' + convert(varchar,SUM(WeeklyTotal),1),...
0
1087
by: guru | last post by:
I want to send the whole resultset i retrieved. now i am retrieving the resultset and able to print 15 records in one frame. if i want to print whole the dump records what i have to do.? please help to this scenario.
2
10631
by: Twan Kennis | last post by:
Question: How do I pass a returning resultset from a nested Stored Procedure (which opens a cursor including option "WITH RETURN TO CALLER") as a returning resultset from it's own? When I execute the top-level Stored Procedure, it executes succesfully, but without any resultset. ========================================================== CREATE PROCEDURE sp_executesql(sqltxt CLOB(2M))
3
2183
by: Augustin Prasanna | last post by:
I need to display some 200 records (dynamic) on the screen.. I need to display records from 2 tables (one to many relationship) output would look like Customer Id Name Phone NO 1 abc 23949495 34945959
6
10029
by: joerg | last post by:
Hello world, my program connects to a db2 database and needs to find out the column names and data types for a specific table. The code works fine with mysql and derby, but returns an empty resultset for the table's metadata with db2. SELECTs on the connection object work, so there is no problem with the database connection.
13
14600
by: ajos | last post by:
hi frnds, im doing some db related operations in my web project,im using mysql 5.0,i have the following piece of code in my action class- for(resultset = statement.executeQuery(s2); resultset.next();) { s10 = resultset.getString(1); s11 = resultset.getString(2); s12 = resultset.getString(3); } resultset.close();
3
4055
by: John | last post by:
Hi I have an sql statement in a string variable SQLStr and I also have an oledbconnection Conn with my database. What can I do from here to run the sql and get a handle to the resultset in my app? I want to be able to go through the records in the resultset in a loop and read the field values. Thanks Regards
0
9551
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10505
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10276
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10253
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10035
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9090
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7580
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5471
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3764
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.