jlrober

Greenhorn
+ Follow
since Jun 25, 2001
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by jlrober

You probably have already looked into the following DatabaseMetaData methods, but in case you overlooked them:
getExportedKeys(String catalog, String schema, String table)
getImportedKeys(String catalog, String schema, String table)
getPrimaryKeys(String catalog, String schema, String table)
The above are only for primary key/foreign key constraints. I haven't come accross a solution for non-key constraints.
jamie
which database product are you using?
In Oracle 8 you can query certain Oracle tables to find the information
Example:
use the query
"SELECT constraint_name, contraint_type, deferrable, validated
FROM dba_constraints
WHERE owner = "Scott"
AND table_name = 'Employees'"
the owner statement in the where clause is optional(only needed if the table exists twice in the same database!). You also have to have permissions to these table to access the data.
Jamie

in a previous posting it was brought to my attention that the getString(1) method may be called only once on a value with out throwing an "NoDataFound" exception when using certain databases. Has anyone else encountered this problem? If so which type of database?
My experience is limited to Oracle 8 and jdbc 2. the preceding combination allows me to call the getXXX() method on the same value until the cows come home!
the original post was http://www.javaranch.com/ubb/Forum3/HTML/001177.html
Jamie
Which database are you using? I've never come accross a problem of calling getXXX more than once and receiving a no data found exception!
Is this common to many database vendors?

Jamie

Just a side note...
the ResultSet.CONCUR_READ_ONLY property will have to be changed if your planning on allowing updates to the selected records. It is the ResultSet.TYPE_SCROLL_INSENSITIVE property that renders the resultset scrollable. You probably already knew that but it may save you some time in the future.
good luck,
Jamie

Originally posted by Yogesh MSharma:
Hi I want to Know How To insert data fetch form Back end to the Grid or JTable i workd lot but not solovig the prob
Please helo out


I don't quite understand what you mean. Do you mean display the ResultSet in a JTable? If so, I can post some code. If you need to display only a portion of the resultset then I can post code for that too.
Jamie

Originally posted by parmeet bedi:
Its not beacuse of .next()
I tried to use first() method but it gives an error
Exception in thread "main" java.lang.UnsupportedOperationException
at sun.jdbc.odbc.JdbcOdbcResultSet.first(Unknown Source)
at tableNames.main(tableNames.java:103)


parmeet:
your problem lies in the type of statement you are creating. By default the cursor is of type forward only which allows you to use the ResultSet.next() method. It however will not let you use the method ResultSet.first() as it may have to move the cursor backwards. If you want to use the .next/.last methods then you have to declare a statement of type scroll insensitive(can move forwards and backwards through the resultset. Here is an example:
ResultSet results;
Statement statement;
statement = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
results = statement.executeQuery(query);
results.last();
transfers = results.getRow(); //returns the number of rows returned by the query
results.first();
//continue processing the results...
hope that helps,
Jamie
"You have to understand that resultset is always a forward-only cursor."
I hope you are not suggesting that all resultsets are type forward only. Surely you are aware of ResultSet.TYPE_SCROLL_INSENSITIVE. Also, I can use the getXXX(1) method as many times on a resultset row as needed. example code snippet that was pulled from one of my programs:
String query = "select * from emp"
statement = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
results = statement.executeQuery(query);
results.last();
results.first();
System.out.println("results.getString(1) = " + results.getString(1));
System.out.println("results.getString(1) = " + results.getString(1));
maybe I misunderstood what you were implying by the above statement but in numerous situations I use a scrollable resultset accessing each data with the getXXX method many times.
If you know that there will be only 1 or 0 rows then you can just check to see if the resultset returned any results:
resultset.next() returns true if there are and records and false if none were found.
if (resultset.next())
{
//1 row returned (really...it means at least one row
//returned from the database)
}
else
{
//0 rows returned
}
hope that helps,
Jamie
Actually, if you close the Statement only, it will automatically call ResultSet.close() on any resultsets using the statement closed. So you don't "HAVE" to close the resultset explicitly, but it may just be good habit.