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: - public static void main(String[] args) {
-
// TODO code application logic here
-
Connection conn = null;
-
Statement stmt = null;
-
ResultSet rs = null;
-
-
try
-
{
-
String driverName = "com.mysql.jdbc.Driver";
-
Class.forName(driverName).newInstance();
-
String username = "root";
-
String password = "password";
-
String url = "jdbc:mysql://localhost:3306";
-
conn = DriverManager.getConnection(url, username, password);
-
-
System.out.println("Creating database");
-
PreparedStatement ps = null;
-
String createDatabase = "CREATE DATABASE dbNetBeans";
-
ps = conn.prepareStatement(createDatabase);
-
ps.executeUpdate();
-
-
System.out.println("Creating table tblNetBeans");
-
String createTable = "CREATE TABLE dbNetBeans.tblTest (testCol varchar(30))";
-
ps = conn.prepareStatement(createTable);
-
ps.executeUpdate();
-
-
System.out.println("Inserting data to tblTest");
-
String insert = "INSERT INTO dbNetBeans.tblTest (testCol) VALUES ('Test info')";
-
ps = conn.prepareStatement(insert);
-
ps.executeUpdate();
-
ps.executeUpdate(); //two records
-
-
System.out.println("Getting info from tblTest");
-
stmt = conn.createStatement();
-
rs = stmt.executeQuery("SELECT * FROM dbNetBeans.tblTest");
-
//rs = stmt.getResultSet(); this didn't help
-
System.out.println("Number of records in rs: " + rs.getFetchSize());
-
-
}
-
catch (ClassNotFoundException e)
-
{
-
System.out.println("Could not find class");
-
e.printStackTrace();
-
}
-
catch (SQLException e)
-
{
-
System.out.println(e.getMessage());
-
e.printStackTrace();
-
}
-
catch (Exception ex)
-
{
-
ex.printStackTrace();
-
}
-
finally
-
{
-
try { conn.close(); stmt.close(); }
-
catch (Exception ignore) { }
-
}
-
}
-
Here's the output: -
init:
-
deps-jar:
-
Compiling 1 source file to /home/steve/DatabaseTest/build/classes
-
compile:
-
Creating database
-
Creating table tblNetBeans
-
Inserting data to tblTest
-
Getting info from tblTest
-
Number of records in rs: 0
-
debug:
-
BUILD SUCCESSFUL (total time: 3 seconds)
-
2 2182
Oops - I'm running Java 1.6.
Never mind -- I misunderstood the purpose of getFetchSize. I thought it was similar to .Net's DataSet.Table.R ows.Count.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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(
|
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...
|
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),...
|
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.
|
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))
| |
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
|
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.
|
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();
|
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
|
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,...
|
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...
| |
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...
|
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,...
|
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...
|
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...
|
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...
|
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...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |