SQL Style, Theta vs. ANSI

Posted in Database with tags , on April 11, 2008 by wsjoung

Theta Style:
SELECT i.order_id, p.product_id, p.name, p.desc
FROM CustomerItem i, Product p
WHERE i.product_id = p.product_id
AND i.order_id = 84463;

ANSI Style:
SELECT i.order_id, p.product_id, p.name, p.desc
FROM CustomerItem i
INNER JOIN Product p ON i.product_id = p.product_id
WHERE i.order_id = 84463;

Sometimes, it’s hard to realized whether there is other style of SQL. Obviously there are two different SQL style. theta is older and more obscure but many people still use it.


Interview questions

Posted in Algorithm with tags , , , on February 6, 2008 by wsjoung
  • what’s difference C++ and java
  • explain about java static
  • is java use call by reference or call by value
  • get the algorithm to fine nth value from the last element in single linked list, and write code

all questions look pretty easy though,

anyway, the last algorithm question. because it’s just one direction single linked list, we should trouble from the start node to the last node. then we can figure out how many elements in that linked list when we reached the last element. then we can simply travel again from the start node to (m-n)th element. complexity is O(n).
I was trying to bring up some other data structure like stack or hash table but, all those are not good in terms of space efficiency. we do not have to wast precious resource which doesn’t increase the performance that much.

DataSource setup on Tomcat

Posted in Server with tags , , , on September 21, 2007 by wsjoung

1. create META-INF/context.xml

<?xml version=”1.0″ encoding=”UTF-8″?>
<Context docBase=”e-sports” path=”/e-sports” debug=”0″ reloadable=”true”
<Logger className=”org.apache.catalina.logger.FileLogger”
prefix=”e-sports_log.” suffix=”.txt” timestamp=”true” />
<Resource name=”jdbc/myoracle”
maxWait=”-1″ />

2. test.jsp
<%@ page import=”java.sql.Connection” %>
<%@ page import=”java.sql.ResultSet” %>
<%@ page import=”java.sql.SQLException” %>
<%@ page import=”java.sql.Statement” %>
<%@ page import=”javax.naming.Context” %>
<%@ page import=”javax.naming.InitialContext” %>
<%@ page import=”javax.naming.NamingException” %>
<%@ page import=”javax.sql.DataSource” %>

Context ctx = null;
DataSource source = null;
Connection con = null;

try {
ctx = new InitialContext();
ctx = (Context) ctx.lookup(“java:comp/env”);
source = (DataSource) ctx.lookup(“jdbc/myoracle”);

System.out.println(“DataSource ===========================”+ source);

con = source.getConnection();
System.out.println(“Connection ============================”+ con);
} catch (NamingException ne) {

javamail smtp with Gmail

Posted in Programming with tags , , , , on August 3, 2007 by wsjoung

package com.mycompany.emailsender;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import java.security.Security;
import java.util.Properties;

import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

* Servlet implementation class for Servlet: GmailSender
public class GmailSender extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet {
/* (non-Java-doc)
* @see javax.servlet.http.HttpServlet#HttpServlet()
public GmailSender() {

/* (non-Java-doc)
* @see javax.servlet.http.HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub

/* (non-Java-doc)
* @see javax.servlet.http.HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
final String SMTP_HOST_NAME = “smtp.gmail.com”;
final int SMTP_HOST_PORT = 465;
final String SMTP_AUTH_USER = “XXXXXX@gmail.com”;
final String SMTP_AUTH_PWD = “XXXXXX”;
final String SSL_FACTORY = “javax.net.ssl.SSLSocketFactory”;

String emailFromAddress = null;
String[] sendTo = null;
String subject = null;
String content = null;

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());

String address = request.getParameter(“address”);
sendTo = address.split(“;”);

emailFromAddress = request.getParameter(“sender”);
this.subject = request.getParameter(“title”);
this.content = request.getParameter(“content”);

try {
for (int i=0; i<sendTo.length; i++) {
System.out.println(“Sucessfully Sent mail to All Users”);

} catch (Exception e) {System.out.println(e);}

public void sendSSLMessage(String dest) throws MessagingException {

Properties props = new Properties();

props.put(“mail.transport.protocol”, “smtps”);
props.put(“mail.smtps.host”, SMTP_HOST_NAME);
props.put(“mail.smtps.auth”, “true”);
props.put(“mail.smtps.quitwait”, “false”);

Session mailSession = Session.getDefaultInstance(props);
Transport transport = mailSession.getTransport();

MimeMessage message = new MimeMessage(mailSession);
InternetAddress addressFrom = new InternetAddress(emailFromAddress);
message.setContent(content, “text/html”);

message.addRecipient(Message.RecipientType.TO,new InternetAddress(dest));



reference: http://www.rgagnon.com/javadetails/java-0083.html

Signed java applet

Posted in Programming with tags , , , on May 15, 2007 by wsjoung

Applet Security Basics

Below are the basic facts regarding applet security and Java Plug-in. More detail can be found in the next chapter, How RSA Signed Applet Verification Works in Java Plug-in.

  • All unsigned applets are run under the standard applet security model.
  • If usePolicy IS NOT DEFINED in the java.policy file, then a signed applet has the AllPermission permission if:
    Java Plug-in can verify the signers, and the user, when prompted, agrees to granting the AllPermission permission.
  • If usePolicy IS DEFINED, then a signed applet has only the permissions defined in java.policy and no prompting occurs.

Moreover, note that Java Plug-in now handles certificate management; i.e., the certificate verification task is no longer passed off to the browser.

keytool -genkey -keyalg rsa -alias MyCert
keytool -certreq -alias MyCert
keytool -import -alias MyCert -file VSSStanleyNew.cer


keytool -selfcert


jarsigner AppletName.jar MyCert
jarsigner -verify -verbose -certs AppletName.jar

Eclipse web.xml validation problem

Posted in Software with tags , , , on February 7, 2007 by wsjoung

The problem is because of “http://java.sun.com/xml/ns/j2ee/j2ee_1_4.xsd&#8221; fil, it points ibm’s schema instead of Sun’s

Window -> Preferences… -> Web and XML -> XML Catalog

URI : http://java.sun.com/xml/ns/j2ee/j2ee_web_services_client_1_1.xsd
Key Type : Schema Location
Key : http://www.ibm.com/webservices/xsd/j2ee_web_services_client_1_1.xsd

Thanks Carey Evans

mod_rewrite: Apache URL Rewriting

Posted in Server with tags , , , on January 24, 2007 by wsjoung

People loves to apply MVC model pretty much on their web application project. They likely put a controller which takes user input from the request and figures out what it means to the model. In this case, URL may looks like this, “index.php?category=sub”. It’s not pretty at all. If we can make this “category/sub”. it would be much better for search engine and users; security reason as well.

Module mod_rewrite URL Rewriting Engine
mod_rewrite, a beginner’s guide (with examples)
mod_rewrite: A Beginner’s Guide to URL Rewriting
mod_rewrite Cheat Sheet