JDBC / CATATAN</>↗JDBC12 Mar 2007
Moving through the result set, you might want to know in what row is the current cursor positioned. To get this information, you can call the ResultSet’s getRow() method. package org.kodejava.jdbc; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; public class ScrollableGetRowExample { private static final String URL = "jdbc:mysql://localhost/kodejava"; private static final […]
JDBC / CATATAN</>↗JDBC08 Mar 2007
On the previous example, we check for the beginning of the result-set. Now using the isAfterLast() method we can check the opposite whether the pointer is at the end of the result set. package org.kodejava.jdbc; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; public class ScrollableAfterLastExample { private static final String URL = […]
JDBC / CATATAN</>↗JDBC06 Mar 2007
When iterating the scrollable result-sets, you can check whether you are in the beginning of the result set or not. The isBeforFirst() method check if the position is at the beginning, if yes this method returns true, otherwise it will return false. package org.kodejava.jdbc; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; public […]
JDBC / CATATAN</>↗JDBC01 Mar 2007
To move the cursor to the end of result-set (after the last record), you can call the afterLast() method of the ResultSet. package org.kodejava.jdbc; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; public class ScrollableAfterLastExample { private static final String URL = "jdbc:mysql://localhost/kodejava"; private static final String USERNAME = "kodejava"; private static final […]
JDBC / CATATAN</>↗JDBC01 Mar 2007
package org.kodejava.jdbc; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; public class ScrollableMoveExample { private static final String URL = "jdbc:mysql://localhost/kodejava"; private static final String USERNAME = "kodejava"; private static final String PASSWORD = "s3cr*t"; public static void main(String[] args) { try (Connection connection = DriverManager.getConnection(URL, U...
JDBC / CATATAN</>↗JDBC25 Feb 2007
In this example, we are using the DatabaseMetaData to retrieve table’s column names. The metadata information can be obtained by calling the connection.getMetaData(). Next, we can then get a ResultSet object by calling metadata.getColumns() method and passing the catalog name, schema pattern, table name pattern, and column name pattern. From this result set COLUMN_NAME, TYPE_NAME, […]