Archive for 'Programming'

Connecting to MySQL using Java

This tutorial will guide you throught the most fundamental steps in connecting to MySQL using Java. The very first thing you should start with is getting the JDBC driver for MySQL.

  1. Go to the MySQL website and download the Java JDBC driver. Link Download the “JDBC Driver for MySQL (Connector/J)”
  2. Create a new Project in Eclipse or Netbeans or anyother IDE that you might be using for Java.
  3. Add the JDBC driver to the library path in your project properties window
  4. Create or use an existing mysql database, with dummie data.
  5. Download this mysql class. MySQLService.java
  6. Create a simple class that initiate the MySQLService class and do a query.
  7. Here is a guide of how to handle the returning value ResultSet of the doQuery

  8. mysql.connect();
    ResultSet result = mysql.doQuery("SELECT * FROM reports_categories");

    while(result.next())
    {
    System.out.println(result.getObject("category_id").toString()+","
    +result.getObject("category_name").toString());
    }
    result.close();
    mysql.close();

  9. The attached jva file MySQLService.java, the function doQuery only accepts SQL SELECT statements for now. I’ll update this article and the java file with other functions that allows for insertion and update of rows.

8-bit Up/Down Counter using VHDL

The following code is a 8-bit counter with the following settings:
- asynchronous set (set count to the last digit of student ID;
- syncchronous clear( set count to 0)
- enable (stop counting)


-- Student ID: 123456789

LIBRARY ieee;
USE ieee.std_logic_1164.all;

ENTITY eight_bit_counter IS
PORT(clk, clear, set, enable : IN STD_LOGIC;
count : OUT INTEGER RANGE 0 TO 127);
END eight_bit_counter;

ARCHITECTURE behavior OF eight_bit_counter IS
BEGIN
PROCESS(clk, clear, set, enable)
VARIABLE cnt : INTEGER RANGE 0 TO 127 :=89; – set cnt range to 7 bits and initialize it to 89
VARIABLE direction : INTEGER RANGE -1 TO 1:= -1; – flag to control up/down direction
BEGIN
IF(set = ‘1′) THEN –check the set input
cnt := 89;
direction := -1;
ELSIF(clk’EVENT AND clk =’1′) THEN
IF(clear = ‘1′) THEN — check if the input clear is high
cnt := 0;
direction := 1;
END IF;
IF(enable = ‘1′) THEN – check if it is enable
cnt := cnt + direction;

IF(cnt = 89) THEN — if it reaches 89 begin countdown
direction := -1; — set direction to negative to count backwards
ELSIF(cnt = 67) THEN — if it reaches 67 begin counting up
direction := 1; — set direction to positive to count foward
END IF;
ELSE
cnt := cnt; – if the counter is disable just display the last value and stop counting
END IF; – if the counter is enable resume last counting
END IF;
count <= cnt; – out put the cnt to the count
END PROCESS;
END behavior;