JDBC / NOTES</>↗JDBC02 Nov 2006
package org.kodejava.jdbc; import java.sql.*; public class GettingTableListExample { 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, USERNAME, PASSWORD)) { // Gets the metadata of the database DatabaseMetaData metaData = connection.getMetaData(); String[]...
JDBC / NOTES</>↗JDBC30 Oct 2006
This example is to show you how to delete or drop a table from your database. Basically we just send a DROP TABLE command and specify the table name to be deleted to the database. The example below show you how to do it in MySQL database. package org.kodejava.jdbc; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; […]
JDBC / NOTES</>↗JDBC29 Oct 2006
In this example you can see how to create a table in MySQL database. We create a table called book with the following fields, id, isbn, title, published_year and price. We start by creating a connection to the database and execute the create table query. package org.kodejava.jdbc; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import java.sql.Statement; […]
JDBC / NOTES</>↗JDBC26 Oct 2006
In this example you can see how to get number of rows or records affected when we update records in the database. The executeUpdate() method of Statement or PreparedStatement return an integer value which tell us how many records was affected by the executed command. Note that when the return value for executeUpdate() method is […]
JDBC / NOTES</>↗JDBC25 Oct 2006
Here is another example on how to read data from a ResultSet returned by executing an SQL query in a database. We start by creating a connection to the database. Creates a PreparedStatement to execute a query to get some data from the books table. After executing the PreparedStatement we will have a ResultSet object. […]
CORE API / NOTES</>↗Core API21 Oct 2006
package org.kodejava.util; import java.util.Arrays; import java.util.Collections; public class ArrayMinMax { public static void main(String[] args) { // Creates an array of integer numbers in it. Integer[] numbers = {8, 2, 6, 7, 0, 1, 4, 9, 5, 3}; // To get the minimum or maximum value from the array we can // use the Collections.min() […]