I am trying to select values from a row in my MySQL table.
SELECT fortnite,psn,steam,twitch,xbox,youtube
FROM `social_media`
WHERE id = '16483378715464928'
When I try to convert the result into a string, the ResultSet only receives the first "fortnite" row. My question is, how do I retrieve the following columns and put them all into one string to return.
Here is my example code:
public static String getSocialMedia(String id) {
String ret = "";
int i = 1;
try {
Statement stmt = null;
ResultSet resultSet = null;
getConnection();
stmt = con.createStatement();
resultSet = stmt.executeQuery("SELECT fortnite,psn,steam,twitch,xbox,youtube FROM `social_media` WHERE id ='" + id + "'");
while(resultSet.next()) {
ret += resultSet.getString(i) + " ";
i++;
}
if(resultSet != null) {
resultSet.close();
}
if(stmt != null) {
stmt.close();
}
} catch (Exception e) {
e.printStackTrace();
}
return ret;
}
This is happening due to this.
while(resultSet.next()) {
ret += resultSet.getString(i) + " ";
i++;
}
In the above code inside while you need to fetch all the values either by name or index. next() function gives you the complete row not a single column.
You should change it to:
while(resultSet.next()) {
for(i = 1, i <=6, i++){
ret += resultSet.getString(i) + " ";
}
}
When i try to convert the result into a string, the ResultSet only
receives the first "fortnite" row. My question is, how do i retrieve
the following columns and put them all into one string to return.
Terminology is important here, because misunderstanding terminology may lead you to misinterpret documentation. In this case, the important terminology distinction is "row" vs. "column".
Your query SELECTs fortnite,psn,steam,twitch,xbox,youtube. Those six identifiers define six columns that each row in your result set will have. It looks like your particular query is selecting by the table's primary key, so you'll only ever have zero or one row, but other queries can return multiple rows.
You want to extract the values of all six columns of one row, but you iterate while(resultSet.next()), and ResultSet.next() moves the result set to the next row, if any, not the next column. Since you have only one row, the loop terminates after only one iteration.
It looks like you want something more like this:
if (resultSet.next()) {
for (i = 1; i <= 6; i++) {
ret += resultSet.getString(i) + " ";
}
}
The if (resultSet.next()) is necessary to move the result set to the first row, and to detect when there isn't any. Then you iterate over the columns of the result, whose number you know statically, based on the query.
Related
I have read a similar post but I still cannot get what is the problem.
I created a table in ms access, named DOCTOR, there are columns: DoctorID(number), Name(text), PhoneNumber(number), Department(text) and Specialization(text)
I connect the database to java through UCanAccess, below is the code to get connection
import java.sql.*;
public class Doctor
{
public static Connection connection; //sharing the memory
public static Connection connect() throws ClassNotFoundException, SQLException
{
String db = "net.ucanaccess.jdbc.UcanaccessDriver";
Class.forName(db);
String url = "jdbc:ucanaccess://C:/Users/user.oemuser/Documents/Doctor.accdb";
connection = DriverManager.getConnection(url);
return connection;
}
}
In my GUI class, i have a method called getConnect to show the data from database to textfield
public void getConnect()
{
try
{
connection = Doctor.connect();
statement=connection.createStatement();
String sql = "SELECT * FROM DOCTOR";
results = statement.executeQuery(sql);
results.next();
id = results.getInt("DoctorID");
name = results.getString("DoctorName");
phone = results.getInt("PhoneNumber");
dept = results.getString("Department");
spec = results.getString("Specialization");
textField1.setText("" +id);
textField2.setText(name);
textField3.setText("" +nf3.format(phone));
textField4.setText(dept);
textField5.setText(spec);
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
and below is the code for the button1 which is the next button.
if(evt.getSource() == button1)
{
try
{
connection = Doctor.connect();
connection.setAutoCommit(false);
statement=connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
String sql1 = "SELECT * FROM DOCTOR";
results = statement.executeQuery(sql1);
if(results.next())
{
textField1.setText("" +results.getInt("DoctorID"));
textField2.setText(results.getString("DoctorName"));
textField3.setText("" +nf3.format(results.getInt("PhoneNumber")));
textField4.setText(results.getString("Department"));
textField5.setText(results.getString("Specialization"));
}
else
{
results.previous();
JOptionPane.showMessageDialog(null, "No more records");
}
connection.commit();
}
catch(Exception ex){
ex.printStackTrace();
}
}
Obviously the best component to use here is a JTable if you want to query all records within a particular database table or at the very least place the result set into an ArrayList mind you database tables can hold millions+ of records so memory consumption may be a concern. Now, I'm not saying that your specific table holds that much data (that's a lot of Doctors) but other tables might.
You can of course do what you're doing and display one record at a time but then you should really be querying your database for the same, one specific record at a time. You do this by modifying your SQL SELECT statement with the addition of the WHERE clause statement and playing off the ID for each database table record, something like this:
String sql = "SELECT * FROM DOCTOR WHERE DoctorID = " + number + ";";
But then again we need to keep in mind that, if the schema for your DoctorID field is set as Auto Indexed which of course allows the database to automatically place a incrementing numerical ID value into this field, the Index may not necessarily be in a uniform sequential order such as:
1, 2, 3, 4, 5, 6, 7, 8, 9, 10,.......
instead it could possibly be in this order:
1, 3, 4, 5, 6, 9, 10, 11, 16, 17,....
This sort of thing happens in MS Access Tables where a table record has been deleted. You would think that the ID slot that is deleted would be available to the next record added to the table and would therefore hold that removed ID value but that is not the case. The Auto Index Increment (autonumber) simply continues to supply increasing incremental values. There are of course ways to fix this sequencing mismatch but they are never a good idea and should truly be avoided since doing so can really mess up table relationships and other things within the database. Bottom line, before experimenting with your database always make a Backup of that database first.
So, to utilize a WHERE clause to play against valid record ID's we need to do something like this with our forward and reverse navigation buttons:
Your Forward (Next) Navigation Button:
if(evt.getSource() == nextButton) {
try {
connection = Doctor.connect();
connection.setAutoCommit(false);
number++;
long max = 0, min = 0;
ResultSet results;
Statement statement=connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
// Get the minimum DoctorID value within the DOCTOR table.
String sql0 = "SELECT MIN(DoctorID) AS LowestID from DOCTOR";
results = statement.executeQuery(sql0);
while (results.next()){ min = results.getLong("LowestID"); }
// Get the maximum DoctorID value within the DOCTOR table.
sql0 = "SELECT MAX(DoctorID) AS HighestID from DOCTOR";
results = statement.executeQuery(sql0);
while (results.next()){ max = results.getLong("HighestID"); }
if (max <= 0) {
JOptionPane.showMessageDialog(null, "No records found in Doctor Table.");
return;
}
if (number > min) { previousButton.setEnabled(true); }
if (number > max) {
nextButton.setEnabled(false);
JOptionPane.showMessageDialog(null, "No more records");
number--;
}
results = null;
while (results == null) {
String sql1 = "SELECT * FROM DOCTOR WHERE DoctorID = " + number + ";";
results = statement.executeQuery(sql1);
long id = 0;
// Fill The GUI Form Fields....
while (results.next()){
//id = results.getLong("DoctorID");
textField1.setText("" +results.getInt("DoctorID"));
textField2.setText(results.getString("DoctorName"));
textField3.setText("" + results.getString("PhoneNumber"));
textField4.setText(results.getString("Department"));
textField5.setText(results.getString("Specialization"));
connection.commit();
return;
}
// ----------------------------------------------------------
if (id != number) { results = null; number++; }
}
}
catch(Exception ex){ ex.printStackTrace(); }
}
Your Reverse (Previous) Navigation Button:
if(evt.getSource() == previousButton) {
try {
connection = Doctor.connect();
connection.setAutoCommit(false);
number--;
long max = 0, min = 0;
ResultSet results;
Statement statement=connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
// Get the minimum DoctorID value within the DOCTOR table.
String sql0 = "SELECT MIN(DoctorID) AS LowestID from DOCTOR";
results = statement.executeQuery(sql0);
while (results.next()){ min = results.getLong("LowestID"); }
// --------------------------------------------------------------------------
// Get the maximum DoctorID value within the DOCTOR table.
sql0 = "SELECT MAX(DoctorID) AS HighestID from DOCTOR";
results = statement.executeQuery(sql0);
while (results.next()){ max = results.getLong("HighestID"); }
// --------------------------------------------------------------------------
if (max <= 0) {
JOptionPane.showMessageDialog(null, "No records found in Doctor Table.");
return;
}
if (number < min) {
previousButton.setEnabled(false);
JOptionPane.showMessageDialog(null, "No more records");
number++;
}
if (number < max) { nextButton.setEnabled(true); }
results = null;
while (results == null) {
String sql1 = "SELECT * FROM DOCTOR WHERE DoctorID = " + number + ";";
results = statement.executeQuery(sql1);
long id = 0;
// Fill The GUI Form Fields....
while (results.next()){
textField1.setText("" +results.getInt("DoctorID"));
textField2.setText(results.getString("DoctorName"));
textField3.setText("" + results.getString("PhoneNumber"));
textField4.setText(results.getString("Department"));
textField5.setText(results.getString("Specialization"));
connection.commit();
return;
}
// ----------------------------------------------------------
if (id != number) { results = null; number--; }
}
}
catch(Exception ex){ ex.printStackTrace(); }
}
Things To DO...
So as to remove duplicate code, create a method named
getMinID() that returns a Long Integer data type. Allow this method to accept two String Arguments (fieldName and
tableName). Work the above code section used to gather the minimum DoctorID value within the DOCTOR table into the new
**getMinID() method. Use this new method to replace the formentioned code for both the Forward (Next) and Revese (Previous)
buttons.
So as to remove duplicate code, create a method named
getMaxID() that returns a Long Integer data type. Allow this method to accept two String Arguments (fieldName and
tableName). Work the above code section used to gather the maximum DoctorID value within the DOCTOR table into the new
getMaxID() method. Use this new method to replace the formentioned code for both the Forward (Next) and Revese (Previous)
buttons.
So as to remove duplicate code, create a void method named
fillFormFields(). Allow this method to accept two arguments, one as Connection (*connection) and another as ResultSet
(results) . Work the above code section used to Fill The GUI
Form Fields into the new fillFormFields() method. Use this new
method to replace the formentioned code for both the Forward (Next)
and Revese (Previous) buttons.
Things To Read That Might Be Helpful:
The SQL WHERE clause statement and the SQL ORDER BY statement for sorting your result set.
Searching For Records
I want to add values in a table that has dynamic columns.
I managed to create a table with dynamic columns but I cannot figure out how to insert data.
//Create Table
sql = "CREATE TABLE MyDB.myTable" +
"(level INTEGER(255) )";
int columnNumber = 5; //Number of columns
//Add columns
for (i=0;i<columnNumber;i++){
String columnName = "Level_" +i:
String sql = "ALTER TABLE MyDB.myTable ADD " + columnName + " INTEGER(30)";
}
//Insert Data
//How to insert data dynamically, without knowing the number of columns?
You can also use database metadata to get the column names. This has the advantage that you even don't need to know the column names, rather they are retrieved dynamically in your code.
public static List<String> getColumns(String tableName, String schemaName) throws SQLException{
ResultSet rs=null;
ResultSetMetaData rsmd=null;
PreparedStatement stmt=null;
List<String> columnNames =null;
String qualifiedName = (schemaName!=null&&!schemaName.isEmpty())?(schemaName+"."+tableName):tableName;
try{
stmt=conn.prepareStatement("select * from "+qualifiedName+" where 0=1");
rs=stmt.executeQuery();//you'll get an empty ResultSet but you'll still get the metadata
rsmd=rs.getMetaData();
columnNames = new ArrayList<String>();
for(int i=1;i<=rsmd.getColumnCount();i++)
columnNames.add(rsmd.getColumnLabel(i));
}catch(SQLException e){
throw e;//or log it
}
finally{
if(rs!=null)
try {
rs.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
throw e
}
if(stmt!=null)
try {
stmt.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
throw e
}
}
return columnNames;
}
Once you have the column names, you can use it as you normally would (List.size() would of course give the number of columns).
UPDATE:
//I will assume that your values (data to be inserted) is a List of Object types and that it is already populated
List<Object> data = new ArrayList<>();
//you will populate this list
//getting the column names
List<String> columnNames = getColumns("MyTable", "MyDB");
String insertColumns = "";
String insertValues = "";
if(columnNames != null && columnNames.size() > 0){
insertColumns += columnNames.get(0);
insertValues += "?";
}
for(int i = 1; i < columnNames.size();i++){
insertColumns += ", " + columnNames.get(i) ;
insertValues += "?";
}
String insertSql = "INSERT INTO MyDB.MyTable (" + insertColumns + ") values(" + insertValues + ")";
try{
PrepareStatement ps = conn.prepareStatement(insertSql);
for(Object o : data){
ps.setObject(o); //you must pass objects of correct type
}
ps.execute(); //this inserts your data
}catch(SQLException sqle){
//do something with it
}
This code assume that you pass objects of correct types to PreparedStatement.setObject(Object o) method. It's also possible to retrieve column types using metadatabase information and then use that info to enforce type checking but that would make your code much more complicated
If you know the number of columns you want to insert, you can make your insert query same way you made your CREATE TABLE. Explicitly name the columns you want to add your data into, and make sure the columns you leave empty are allowed to be empty (NULL or default=0)
INSERT INTO MyDB.myTable (Level_1, Level_2, ...) VALUES (Val_1, Val_2, ...);
The alternative approach would be to store each inserted value in a separate row. In that way you don't vhave to change the number of columns in your table.
You need a table where you have a ID for every group of values:
- ID
- Level
- Value
You could have a separate table where you can register each ID:
- ID (bigInt, auto increment, primary key)
- info field
- timestamp
Now, for every set of data you want to insert, first insert need a Unique ID. If you use the second table, inserting a new row would give you a new ID:
INSERT INTO register_table (ID, info, timestamp) VALUES (NULL, 'some info', NOW());
This will give you a new ID (last_inserted_id).
With this ID now insert all values in the other table:
for(i=0i<columnNumber;i++){
"INSERT INTO _table (ID, Level, _Value) VALUES ("+ the_ID +", "+ i +", "+ the_VALUE +");";
}
If you want to fetch the data:
"SELECT Level, _Value FROM _table WHERE ID="+ the_ID +" ORDER BY Level;";
I'm trying to store rows from a table into an array. I can get the first result and store that but I cannot seem to be able to store any of the other data.
This is the code I've written
try
{
test = "select * from Arsenal order by 'MatchNumber' ASC";
rs = st.executeQuery(test);
while (rs.next())
{
//This retrieves each row of Arsenal table and adds it to an array in the Team Results class.
matchno = rs.getString("MatchNumber");
hometeam = rs.getString("HomeTeam");
awayteam = rs.getString("AwayTeam");
homegoals = rs.getString("HomeGoals");
awaygoals = rs.getString("AwayGoals");
result = rs.getString("Result");
teams = (matchno + "," + hometeam + "," + awayteam + "," + homegoals + "," + awaygoals + "," + result); // Takes all the variables containging a single customers information and puts it into a string, seperated by commas.
TeamResults.add(matchno,hometeam,awayteam,homegoals,awaygoals,result);
}
}
Any idea where I'm going wrong?
Change the while-condition to hasNext() and use next() inside of the loop to move the database cursor forward.
Try to use this method bellow :
public void SelectData(String sqlcounter ,String sql){
try {
RsCounter=stmt.executeQuery(sqlcounter);
System.out.println(sqlcounter);
while(RsCounter.next()){
countrow=RsCounter.getInt("COUNTR");
System.out.println(countrow+"\n");
}
System.out.println(sql);
RsSelecting = stmt.executeQuery(sql);
data=new String[countrow][RsSelecting.getMetaData().getColumnCount()];
header= new String[RsSelecting.getMetaData().getColumnCount()];
i=0;
while(RsSelecting.next()){
for(j=0;j<RsSelecting.getMetaData().getColumnCount();j++){
data[i][j]=(RsSelecting.getString(j+1));
header[j]=RsSelecting.getMetaData().getColumnName(j+1);
System.out.print(data[i][j]+"\n");
}
i++;
}
i=j=0;
} catch (SQLException ex) {
ex.printStackTrace();
Logger.getLogger(Connect.class.getName()).log(Level.SEVERE, null, ex);
}
}
where
sqlcounter ="select COUNT(*) as COUNTR from Arsenal order by 'MatchNumber' ASC";
and
sql ="select * from Arsenal order by 'MatchNumber' ASC";
Verify the column names once. Sometimes ALIAS doesn't work out, I am not sure why.
Get the meta data from the result set:
ResultSetMetaData metaData = resultSet.getMetaData();
int size = metaData.getColumnCount();
for (int i = 0; i < size; i ++)
System.out.println(metaData.getColumnName(i);
Also just for performance, list out the column names instead of using * in the SELECT query. Also, you can take a look at com.sun.rowset.CachedRowSetImpl. It's used like:
CachedRowSetImpl crs = new CachedRowSetImpl();
crs.populate(resultSet);
I think it also implements CachedRowSet, but I am not entirely sure.
I'm working on a project where a user can assemble the components of a yoga class. It's spread across several files and thus too large to put it all here. The trouble I'm having is in one method where I need to iterate over the horizontal columns of a result set that is returning only ONE ROW from a MySQL database.
I understand that I have to position the cursor on the first row of the result set (which I believe I am doing). Since I have only one row in the result set (my variable is rset), I should be using rset.next() only one time, correct? And then I should be able to use a simple loop to iterate over each column and append the value to my String Builder. I want to skip the first column and append each subsequent value until the loop reaches columns with null values. I cannot find why my code keeps returning a "Before start of result set" exception.
Can anyone spot anything wrong?
I'll post the method as well as the method called by this method. (I posted this in a different question, but I believe the nature of my question has changed, so I'm re-posting this with a different title.)
// Query that returns the poses within a specific section
public String listPosesInSection(String tableName, String sectionName) {
String strList;
StringBuilder strBuilderList = new StringBuilder("");
// Run the query
try {
statement = connection.createStatement();
// Query will collect all columns from one specific row
rset = statement.executeQuery("SELECT * FROM " + tableName + " WHERE " + tableName + "_name = '" + sectionName + "'");
rset.next();
System.out.println("Column count is " + countColumnsInTable(tableName));
for (int i = 2; i <= countColumnsInTable(tableName); i++) {// First value (0) is always null, skip first column (1)
System.out.println("test");
strBuilderList.append(rset.getString(i) + "\n"); // This is line 126 as indicated in the exception message
}
} catch (SQLException e) {
e.printStackTrace();
}
strList = strBuilderList.toString();
return strList.replaceAll(", $",""); // Strips off the trailing comma
}
// Method for getting the number of columns in a table using metadata
public int countColumnsInTable(String sectionType) {
int count = 16;
try {
statement = connection.createStatement();
rset = statement.executeQuery("SELECT * FROM " + sectionType);
rsMetaData = rset.getMetaData();
count = rsMetaData.getColumnCount();
} catch (SQLException e) {
e.printStackTrace();
}
return count;
}
And here is the first part of the exception message:
Column count is 26
java.sql.SQLException: Before start of result set
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1078)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:989)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:975)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:920)
at com.mysql.jdbc.ResultSetImpl.checkRowPos(ResultSetImpl.java:855)
at com.mysql.jdbc.ResultSetImpl.getStringInternal(ResultSetImpl.java:5773)
at com.mysql.jdbc.ResultSetImpl.getString(ResultSetImpl.java:5693)
at YogaDatabaseAccess.listPosesInSection(YogaDatabaseAccess.java:126)
at YogaSectionDesigner$5.actionPerformed(YogaSectionDesigner.java:231)
Looks to me like you're re-using the rset between your two methods. So when countColumnsInTable has completed, the rset variable is pointing to a different result set than it was before, in listPosesInSection. And that result set has not been advanced with next, hence the error message you're getting. You probably want to assign it to a local ResultSet within that method instead.
public int countColumnsInTable(String sectionType) {
int count = 16;
try {
Statement statement = connection.createStatement();
ResultSet rset = statement.executeQuery("SELECT * FROM " + sectionType);
ResultSetMetaData rsMetaData = rset.getMetaData();
count = rsMetaData.getColumnCount();
} catch (SQLException e) {
e.printStackTrace();
}
// Remember to clean up
return count;
}
try this
public String listPosesInSection(String tableName, String sectionName) {
String strList;
StringBuilder strBuilderList = new StringBuilder("");
// Run the query
try {
statement = connection.createStatement();
// Query will collect all columns from one specific row
rset = statement.executeQuery("SELECT * FROM " + tableName + " WHERE " + tableName + "_name = '" + sectionName + "'");
while (rset.next()){
System.out.println("Column count is " + countColumnsInTable(tableName));
for (int i = 2; i <= countColumnsInTable(tableName); i++) {// First value (0) is always null, skip first column (1)
System.out.println("test");
strBuilderList.append(rset.getString(i) + "\n");
}
}
} catch (SQLException e) {
e.printStackTrace();
}
strList = strBuilderList.toString();
return strList.replaceAll(", $",""); // Strips off the trailing comma
}
rset is a ResultSet object
i think you are using the same ResultSet object in listPosesInSection and also in countColumnsInTable
so what is happening here is in listPosesInSection rset holds a result and you have also move the cursor but again in countColumnsInTable you are using the same rset so it is overwritten ie it holds a new result now, you are getting the number of columns but since it holds a new result now the cursor will be before the 1st record so use different Resultset object in countColumnsInTable
In order to query the database meta data in Sybase ASE, I found this relevant answer (not the accepted one), to be ideal:
From a Sybase Database, how I can get table description ( field names and types)?
Unfortunately, I can't seem to find any documentation, how I'm supposed to call sp_help from JDBC. According to the documentation, sp_help returns several cursors / result sets. The first one contains information about the table itself, the second one about the columns, etc. When I do this:
PreparedStatement stmt = getConnection().prepareStatement("sp_help 't_language'");
ResultSet rs = stmt.executeQuery();
while (rs.next()) {
System.out.println(rs.getObject(1));
// ...
}
I only get the results from the first cursor. How to access the other ones?
When you have multiple result sets you need to use the execute() method rather than executeQuery().
Here's an example:
CallableStatement cstmt;
ResultSet rs;
int i;
String s;
...
cstmt.execute(); // Call the stored procedure 1
rs = cstmt.getResultSet(); // Get the first result set 2
while (rs.next()) { // Position the cursor 3
i = rs.getInt(1); // Retrieve current result set value
System.out.println("Value from first result set = " + i);
// Print the value
}
cstmt.getMoreResults(); // Point to the second result set 4a
// and close the first result set
rs = cstmt.getResultSet(); // Get the second result set 4b
while (rs.next()) { // Position the cursor 4c
s = rs.getString(1); // Retrieve current result set value
System.out.println("Value from second result set = " + s);
// Print the value
}
rs.close(); // Close the result set
cstmt.close(); // Close the statement
You also need to call getUpdateCount() as well as getMoreResults() to read the entire result set. Here is some code I used to call sp_helpartition to retrieve partition information from a SYBASE DB.
try {
connection = getPooledConnection(poolName);
statement = connection.createStatement();
CallableStatement callable = connection.prepareCall(
"{ call sp_helpartition(?) }");
callable.setString(1,tableName);
callable.execute();
int partitions = 0;
/*
* Loop through results until there are no more result sets or
* or update counts to read. The number of partitions is recorded
* in the number of rows in the second result set.
*/
for (int index = 0 ; ; index ++){
if (callable.getMoreResults()){
ResultSet results = callable.getResultSet();
int count = 0 ;
while (results.next()){
count++;
}
if (index == 1){
partitions = count;
}
} else if (callable.getUpdateCount() == -1){
break ;
}
}
return partitions ;
} catch (Exception e) {
return 0 ;
} finally {
statement.close();
connection.close();
}
Thanks to Martin Clayton's answer here, I could figure out how to query Sybase ASE's sp_help function generically. I documented some more details about how this can be done in my blog here. I worked support for multiple JDBC result sets into jOOQ. In the case of sp_help, calling that function using the jOOQ API might look like this:
Factory create = new ASEFactory(connection);
// Get a list of tables, a list of user types, etc
List<Result<Record>> tables = create.fetchMany("sp_help");
// Get some information about the my_table table, its
// columns, keys, indexes, etc
List<Result<Record>> results = create.fetchMany("sp_help 'my_table'");