import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class InsertClobToMySqlServlet extends HttpServlet {
public static Connection getConnection() throws Exception {
String driver = "org.gjt.mm.mysql.Driver";
String url = "jdbc:mysql://localhost/databaseName";
String username = "root";
String password = "root";
Class.forName(driver);
Connection conn = DriverManager.getConnection(url, username, password);
return conn;
}
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException,
ServletException {
String clobData = null;
Connection conn = null;
String id = "001";
String name = "fileName";
String fileAsURL = "http://yourwebsite/fileName.dat";
ServletOutputStream out = response.getOutputStream();
response.setContentType("text/html");
out.println("Insert Clob To MySql Servlet");
try {
conn = getConnection();
clobData = getClobsContentAsString(fileAsURL);
insertCLOB(conn, id, name, clobData);
out.println("OK: inserted a new record with id=" + id + "
");
} catch (Exception e) {
e.printStackTrace();
out.println("Error: " + e.getMessage() + "