Thursday, January 21, 2010

Sample Program to insert data in the database using java

package Queries;
import java.util.Scanner;
import java.sql.*;

public class InsertRoom {

static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
static final String DATABASE_URL = "jdbc:mysql://localhost/doscstschedule";
static private PreparedStatement insertNewRoom = null;
static String roomCode;
static String deptCode;

public static void main(String[] args) {

Connection connection = null; // manages connection

// connect to database doscstschedule and query database
try {

Class.forName(JDBC_DRIVER); // load database driver class

// establish connection to database
connection = DriverManager.getConnection(DATABASE_URL, "root", "");
Scanner input = new Scanner(System.in);
System.out.print("Enter room code: ");
roomCode = input.next();
System.out.print("Enter department code: ");
deptCode = input.next();

// create Statement for querying database
insertNewRoom = connection.prepareStatement("insert into room values(?,?)");
insertNewRoom.setString(1, roomCode);
insertNewRoom.setString(2, deptCode);

insertNewRoom.executeUpdate();

System.out.println("Data successfully added");
} // end try
catch (SQLException sqlException) {
sqlException.getMessage();
System.exit(0);
} // end catch
catch (ClassNotFoundException classNotFound) {
classNotFound.getMessage();
System.exit(0);
} // end catch
finally // ensure statement and connection are closed properly
{
try {
insertNewRoom.close();
connection.close();
} // end try
catch (Exception exception) {
exception.getMessage();
System.exit(0);
} // end catch
} // end finally
}
}

Friday, January 15, 2010

Displaying data in database using java and mySQL

//This is only an example program on displaying data from database using java and mysql
//important information should be considered.

import java.sql.*;

public class DisplaySubject {

static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
static final String DATABASE_URL = "jdbc:mysql://localhost/doscstschedule";

public static void main(String[] args) {

Connection connection = null; // manages connection
Statement statement = null; // query statement

// connect to database books and query database
try {
Class.forName(JDBC_DRIVER); // load database driver class

// establish connection to database
connection =
DriverManager.getConnection(DATABASE_URL, "root","");

// create Statement for querying database
statement = connection.createStatement();

// query database
ResultSet resultSet = statement.executeQuery(
"SELECT subjCode,subjDesc, lecUnits, labUnits FROM subject");

// process query results
ResultSetMetaData metaData = resultSet.getMetaData();
int numberOfColumns = metaData.getColumnCount();
System.out.println("Subject Table of DOSCST Class Schedule Database:");

for (int i = 1; i <= numberOfColumns; i++) {
System.out.printf("%-30s\t", metaData.getColumnName(i));
}
System.out.println();

while (resultSet.next()) {
for (int i = 1; i <= numberOfColumns; i++) {
System.out.printf("%-30s\t", resultSet.getObject(i));
}
System.out.println();
} // end while
} // end try
catch (SQLException sqlException) {
sqlException.printStackTrace();
System.exit(1);
} // end catch
catch (ClassNotFoundException classNotFound) {
classNotFound.printStackTrace();
System.exit(1);
} // end catch
finally // ensure statement and connection are closed properly
{
try {
statement.close();
connection.close();
} // end try
catch (Exception exception) {
exception.printStackTrace();
System.exit(1);
} // end catch
} // end finall
}
}

Tuesday, January 12, 2010

Java JDBC using MySQL Database

Important notes:
  1. You need to download the jdbc connector of mysql and java in http://dev.mysql.com/downloads/connector/j/
  2. Add this package to your libraries
  3. The information below is all about how to access the driver.

import java.sql.*;
import javax.swing.JOptionPane;
public class Main {

/**
* @param args the command line arguments
*/
public static void main(String[] args) throws Exception {
StringBuffer output = new StringBuffer();
output.append("Tesing MySQL Driver installation");
try {
String className = "com.mysql.jdbc.Driver";
Class driverObject = Class.forName(className);
output.append("Driver: "+driverObject+"\n");
output.append("Driver Installation Successful");
JOptionPane.showMessageDialog(null, output);
}
catch(Exception x){
output = new StringBuffer();
output.append("Driver Installation FAILED\n");
JOptionPane.showMessageDialog(null,output);
System.out.println("Failed Driver Error:" +x.getMessage());
}

}
}


* on this part is an example of how to connect the mysql database using java

import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.SQLException;

public class JDBCDriverInformation {

static String userid = "root";
static String password = "";
static String url = "jdbc:mysql://localhost:3306/databaseapp";
static Connection con = null;
static String className = "com.mysql.jdbc.Driver";

public static void main(String[] args) throws Exception {
Connection con = getMySQLJDBCConnection();
if (con != null) {
System.out.println("Got Connection");
DatabaseMetaData meta = con.getMetaData();
System.out.println("Driver Name : " + meta.getDriverName());
System.out.println("Driver Version : " + meta.getDriverVersion());
} else {
System.out.println("Could not get connection");
}
}

public static Connection getMySQLJDBCConnection() {

try {
Class.forName(className);

} catch (java.lang.ClassNotFoundException e) {
System.err.print("ClassNotFoundException: ");
System.err.println(e.getMessage());
}

try {
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/databaseapp", userid, password);
} catch (SQLException ex) {
System.err.println("SQLException: " + ex.getMessage());

}

return con;
}
}

Hope you can run successfully in this given example.

Thursday, August 20, 2009

My New Website

This is my first time created a web application..

I need comments for this. Please send me comments at my email: jonathancabrera85@yahoo.com

Website: www.doscst.co.nr/gctc

thanks

nathan

Tuesday, March 24, 2009

Am I an IT Professional?


Before I answer the question, let me first define the profession. According to Webster's Dictionary, a "profession is a calling requiring specialized knowledge and often long and intensive academic preparation". The United States Code of Federal Regulations [29 CFR Sec. 541.3] defines a person " employed in a professional capacity" as one who meets these four criteria:

  1. One's primary duties consist of the performance of work requiring knowledge of an advanced type in a field of science or learning customarily acquired by a prolonged course of specialized intellectual instruction and study or work.
  2. One's instruction, study, or work is original and creative in character in a recognized fields of artistic endeavor and the result of which depends primarily on the invention, imagination, or talent of the employee.
  3. One's work requires the consistent exercise of discretion and judgment on its performance.
  4. One's work is predominately intellectual and varied in character and is of such character that the output produced or the result accomplished cannot be standardized in relation to a given period of time.

reference: Ethics in Information Technology Book by George Reynolds

In other words, a professional is someone who requires advanced training and experience, must exercise discretion and judgment in the course of his or her work, and whose work cannot be standardized. Many people would add that they expect a professional to contribute to society, to participate in a life-long training program (both formal and informal), to keep abreast of developments in their field, and to help develop other professionals. In addition, many professional roles carry with them special rights and special responsibilities. Doctors, for example, are allowed to are also expected to help individuals who are hurt in accidents or emergencies. Accountants, lawyers, priests and licensed engineers also have special rights and responsibilities.

Given the definition of "professional," My answer is,YES, I am an IT Professional. There are many business workers whose duties,background and training, and work could qualify them to be classified as professionals. These people include marketing analysts, financial consultants, and IT specialists. A partial list of IT specialists includes programmers, systems analysts, software engineers, database administrators, LAN Administrators and Chief Information Officers (CIOs).

From my own standpoint, I am IT professional in the sense that my duties consist of the performance of work requiring knowledge of an advanced type in a field of science and I also exercise the field. I've worked as an computer technician, IT consultant of one business in our place and I am a Instructor. I've passed some certification in TESDA also. I'll always practicing this field today and forever with ETHICAL WAYS

From a practical standpoint, the IT industry recognizes people from a wide set of backgrounds,education and personal experience in many different roles as IT professionals-provided they can do the job required by such a role.

"I AM PROUD TO SAY THAT I AM AN IT PROFESSIONAL"




Thursday, March 19, 2009

Case 3 - Orchid Seller


Designing Relational Database



















Creating Tables Using MS Access

1. Orchid






2. OrchidItem













3. Wholesaler













Query 1: Greenhouse Requirements

























Result:








Query 2: Orchids That Died













Query 3: Orchids Not in Bloom












Query 4: Best Sellers













Query 5 : Most Profitable Orchids Groups















Report: Profit by Supplier




Thursday, February 19, 2009

Case 2 - The Outsourcing Bookkeeping and Payroll Company

Designing Database Tables

Created Tables using Ms Access





Form: Jobs Input


Query 1: Sales Calls





Query 2: Hours Worked Per Client














Report 1: Clients by ZIP


Report 2: Workers and Times for Client