import java.io.InputStream;
import java.net.URL;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;

public class TestURL {
	public static void main(String[] args) throws Throwable {
		String driver = "com.mysql.jdbc.Driver";
		String url = "jdbc:mysql://localhost/bambarbia?user=root&password=mysql&useServerPrepStmts=false";

		Class.forName(driver).newInstance();
		Connection conn = DriverManager.getConnection(url);

		conn.createStatement().execute("DELETE FROM test");
		
		PreparedStatement ps = conn
				.prepareStatement("INSERT INTO test (text) VALUES (?)");

		URL httpUrl = new URL(
				"http://www.cdw.com/shop/products/default.aspx?EDC=951678");
		InputStream is = httpUrl.openStream();
		
		
		ArrayList zzz = new ArrayList();
		
		int nextByte;
		while ((nextByte = is.read()) != -1) {
			zzz.add(new Byte((byte)nextByte));
		}
		
		byte[] content = new byte[zzz.size()];
		
		for (int i = 0; i< zzz.size(); i++){
			content[i] = ((Byte)zzz.get(i)).byteValue();
		}
		                      
		String html = new String(content, "UTF-8");
		//System.out.println("Content retrieved from Web: " + html);
		
		byte[] byteUTF = html.getBytes();
		
		ps.setString(1, html);
		ps.execute();
		
		ps.setString(1, new String(byteUTF,"windows-1252"));
		ps.execute();
		
		ResultSet rs = conn.createStatement().executeQuery(
				"SELECT text FROM test");

		while (!rs.isLast()) {
			rs.next();
			System.out.println(rs.getString(1));
		}
		
	}
}
