JDBC / CATATAN</>↗JDBC24 Feb 2007
For instance, you have a number or double typed column in a database table, and you want to get the precision and the scale of that column. Here is an example for you. package org.kodejava.jdbc; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.ResultSetMetaData; import java.sql.SQLException; import java.sql.Statement; public class ScaleAndPrecisionExample { private static final String […]
JDBC / CATATAN</>↗JDBC23 Feb 2007
package org.kodejava.jdbc; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.ResultSetMetaData; import java.sql.SQLException; import java.sql.Statement; public class TableNameOfColumnExample { 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 connectio...
JDBC / CATATAN</>↗JDBC18 Feb 2007
In this example we’ll show how to use ResultSetMetaData.isNullable() method to know if a column can be null or not. This method returns an integer which values defined in the constants of ResultSetMetaData.columnNullable, ResultSetMetaData.columnNoNulls and ResultSetMetaData.columnNullableUnknown. package org.kodejava.jdbc; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.ResultSetMetaData; import java.sql.SQLException; imp...
JDBC / CATATAN</>↗JDBC13 Feb 2007
The ResultSetMetaData.isAutoIncrement() method can tell us if a column value is automatically numbered or not. This method return true when the column is an auto-increment column, otherwise it returns false. See the example below where we check if the first column (id) is an auto-increment column. package org.kodejava.jdbc; import java.sql.*; public class IsAutoIncrementExample { private […]
JDBC / CATATAN</>↗JDBC13 Feb 2007
This example show how we can use the ResultSetMetadata class to get the number of columns and column names of the selected table. The ResultSetMetaData class can also be used to get the column type and its properties. Using the ResultSetMetaData class might help you to create an inquiry program where you don’t have all […]
SERVLET / CATATAN</>↗Servlet10 Feb 2007
package org.kodejava.servlet; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; @WebServlet(name = "ResponseStatusServlet", urlPatterns = "/response-status") public class ResponseStatus extends HttpServlet { @Override protected void doGet(HttpServletRequest request, HttpServletResponse...