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; // DDL: create table test (id INT AUTO_INCREMENT PRIMARY KEY, text LONGTEXT); 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(); } ps.setString(1, new String(content,"windows-1252")); ps.execute(); ResultSet rs = conn.createStatement().executeQuery( "SELECT text FROM test"); while (!rs.isLast()) { rs.next(); System.out.println(rs.getString(1)); } } }