Practical Web Programming
Showing posts with label database. Show all posts
Showing posts with label database. Show all posts

Sunday, August 07, 2016

Install Latest MySQL in Ubuntu Server

This assumes that you already have a running Ubuntu server with Apache installed. To install basic security in Ubuntu, see Basic Security Installs for Ubuntu. This instructions was extracted from here.

1. Update the package index on your server
sudo apt-get update

2. Install the package
sudo apt-get install mysql-server 

3. Run the included security script. This changes some of the less secure default options for things like remote root logins and sample users.
sudo mysql_secure_installation

4. If you're using a version of MySQL earlier than 5.7.6, you should initialize the data directory by running command below.
sudo mysql_install_db

Thursday, July 31, 2008

Ebook: Database Normalization Explained

If you're a programmer, aside from your favorite EDI and PL, database is one of your everyday companion. Almost all program these days uses a form of database, be it a flat file or RDBMS.

Being a good programmer, it's not enough that you only know the DML and DDL statements. You should also know and master the art of Database Normalization. Database normalization techniques is essential in order to achieve a high performance database design for your programs. If your database design doesn't conform to at least the Third Normal Form, you will have a hard time getting the data you want and it will be harder to achieve a high performance and scalable application.

Finally, there's an e-book that could give you the right knowledge about Database Normalization. This e-book shows you that normalization is a far too easy approach, and it is richly documented with graphical Entity Relationship and Server Diagram examples.

This knowledge-packed e-book is a great resource for DBAs and programmers.

Click here to get a copy of the Database Normalization Ebook.

Tuesday, October 23, 2007

How To Connect To A Database In Java

This source codes, written in Java, demonstrates how to connect to a database using JDBC and ODBC. The source codes is well commented for you to follow easily.

import java.sql.*;

public class jdbcConnect {
//CLASS CONSTRUCTOR
public jdbcConnect() {
}

//THIS PROC WILL SET THE CONNECTION TO THE DATABASE,
//QUERY AND PRINT THE RESULT TO THE STANDARD OUTPUT
private void loadData()
{
Connection con = null;
Statement stmt = null;
ResultSet rst = null;

//SET ERROR TRAP FOR CONNECTION TO THE DATABASE
try
{
//FOR ODBC CONNECTION
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
//dsn_employee = data source name(dsn)
//un = username
//pw = password
con = DriverManager.getConnection("jdbc:odbc:dsn_employee;
UID=un;PWD=pw");

//CHECK IF THE CONNECTION TO THE DATABASE IS SUCCESSFUL
if(!con.isClosed())
{
//MAKE THE ACTUAL CONNECTION TO THE DATABASE
stmt = con.createStatement(rst.TYPE_SCROLL_SENSITIVE,
rst.CONCUR_READ_ONLY);
//EXECUTE THE SQL QUERY
rst = stmt.executeQuery("SELECT fullname FROM employee");

//CHECK IF CURRENT ROW IS THE LAST
while(!rst.isLast())
{
//SET THE ERROR TRAP FOR READING THE RECORDSET
try
{
//GO TO THE NEXT RECORD OF THE RECORDSET
rst.next();
//PRINT THE RECORD TO THE STANDARD OUTPUT
System.out.println(rst.getInt("fullname"));
}
//HANDLE TRAPPED ERROR ON READING THE RECORDSET
catch(Exception e)
{
//PRINT THE ERROR MESSAGE
System.out.println("ERROR: " + e.getMessage());
}
}
}
}
//HANDLE TRAPPED ERROR ON DATABASE CONNECTION
catch(Exception e)
{
//PRINT THE ERROR MESSAGE
System.err.println("ERROR: " + e.getMessage());
}
finally
{
try
{
if(con != null)
{
//CLOSE THE CONNECTION
con.close();
}
}
catch(SQLException e)
{
//PRINT THE ERROR MESSAGE
System.out.println("ERROR: " + e.getMessage());
}
}
}

//START OF PROGRAM
public static void main(String[] args) {
jdbcConnect dbConnect = new jdbcConnect();
dbConnect.loadData();
}
}

Recent Post