CORE API / CATATAN</>↗Core API05 Nov 2006
package org.kodejava.lang; public class StringToInteger { public static void main(String[] args) { // Some random selected number, could representing a decimal, // hexadecimal or octal number. String myLuckyNumber = "13"; // We convert a string to an integer by invoking parseInt() method // of the Integer class. int number = Integer.parseInt(myLuckyNumber); System.out.println("My lucky number is: […]
ZIP AND GZIP / CATATAN</>↗Zip and GZIP03 Nov 2006
package org.kodejava.util.zip; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; public class ZippingFileExample { public static void main(String[] args) { String source = "data.txt"; String target = "data.zip"; try (ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(target)); InputStream is = ZippingFileExample.class.getResourceAsStream("/" + source)) { if...
JDBC / CATATAN</>↗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 / CATATAN</>↗JDBC30 Okt 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 / CATATAN</>↗JDBC29 Okt 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 / CATATAN</>↗JDBC26 Okt 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 […]