|
By the way you can save on some code because ResultSet will never be null after
rs = statement.executeQuery(stm); (it might be empty but not null), so
if (rs.next()) {
return rs.getString(1).trim();
}
will serve 2 purpose, check if record was found and read it in the same time
-----Original Message-----
From: Mihael Knezevic [mailto:m.knezevic@porta.de]
Sent: Wednesday, January 15, 2003 9:05 AM
To: Java Programming on and around the iSeries / AS400
Subject: RE: result set = null (sometimes)
right. now that you say it ...
i should have seen it myself.
thanx.
-----Original Message-----
From: Alex Pinsky [mailto:apinsky@aeropostale.com]
Sent: Wednesday, January 15, 2003 2:51 PM
To: Java Programming on and around the iSeries / AS400
Subject: RE: result set = null (sometimes)
Hi Mihael,
As I can see in your first method you forgot to assign
statement.executeQuery(stm) call to a ResultSet object reference. The
code should look like this:
rs = statement.executeQuery(stm);
and then you are ready to process your ResultSet object to retrieve
data. Alex
-----Original Message-----
From: Mihael Knezevic [mailto:m.knezevic@porta.de]
Sent: Wednesday, January 15, 2003 8:32 AM
To: java400-l@midrange.com
Subject: result set = null (sometimes)
hi,
i got a little problem i was pondering about some days now and i still
don't now why it is like that.
i got a class RootAccess through which i would like to get some data
from our DB2/400.
it looks like this:
public class RootAccess
{
DatabaseMetaData dmd;
Connection connection;
ResultSet rs;
Statement statement;
String stm;
public RootAccess()
{
try
{
DriverManager.registerDriver(new
AS400JDBCDriver());
connection = DriverManager.getConnection
("jdbc:as400://PORTA","user","pwd");
dmd = connection.getMetaData();
statement = connection.createStatement();
}
catch (SQLException sqle)
{
System.out.println("Problems during database
connection initialization.");
System.out.println(sqle.getLocalizedMessage());
}
}
public String getCompanyName(int companyID)
{
stm = "Select VDDAT from UDVM400DAT.MVDATR where VDSAA =
3 and VDFIR = 10";
try
{
statement.executeQuery(stm);
if(rs != null)
{
rs.next();
return rs.getString(1).trim();
}
return "";
}
catch(SQLException sqle)
{
System.out.println(sqle.getLocalizedMessage());
return "";
}
finally
{
rs = null;
}
}
public Vector getCompanyNames()
{
Vector namesVec = new Vector();
stm = "Select substring(VDDAT,1,20) from
UDVM400DAT.MVDATR where VDSAA = 3";
try
{
rs = statement.executeQuery(stm);
if(rs != null)
{
while (rs.next())
namesVec.add(rs.getString(1).trim());
}
}
catch (SQLException sqle)
{
}
finally
{
rs = null;
}
return namesVec;
}
}
my main class looks like this:
public class Test
{
public static void main(String[] args)
{
RootAccess access = new RootAccess();
System.out.println("Firmengruppe 010:" +
access.getCompanyName(10));
Vector vec = access.getCompanyNames();
for (int i = 0; i < vec.size(); i++)
{
System.out.println("Firmengruppenname:" +
vec.get(i).toString());
}
}
}
now my problem:
when i execute the first method, the result set is null. if execute the
same sql statement via several other applications or directly on the
as400 i get the right result (not null). but when i execute the second
method i get the right results. now why does the first sql request
doesn't work. did i forgot something?
os400 v4r5
java (on pc) ibm 1.3.0
jtopen 3.1
_______________________________________________
This is the Java Programming on and around the iSeries / AS400
(JAVA400-L) mailing list To post a message email: JAVA400-L@midrange.com
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo.cgi/java400-l
or email: JAVA400-L-request@midrange.com
Before posting, please take a moment to review the archives
at http://archive.midrange.com/java400-l.
_______________________________________________
This is the Java Programming on and around the iSeries / AS400
(JAVA400-L) mailing list To post a message email: JAVA400-L@midrange.com
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo.cgi/java400-l
or email: JAVA400-L-request@midrange.com
Before posting, please take a moment to review the archives
at http://archive.midrange.com/java400-l.
_______________________________________________
This is the Java Programming on and around the iSeries / AS400 (JAVA400-L)
mailing list
To post a message email: JAVA400-L@midrange.com
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo.cgi/java400-l
or email: JAVA400-L-request@midrange.com
Before posting, please take a moment to review the archives
at http://archive.midrange.com/java400-l.
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2025 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.