inserting byte array into mysql DB
-
Hi, I'm new in Java and have the following task to do: I have some data stored in gzip byte array and I have to insert it into MySQL database. I'm using DBCP (Apache Tomcat 6.0.20) not JDBC. I tried the following code:
PreparedStatement pstmt =(PreparedStatement)con.prepareStatement("insert into test_tb (id, data, compressed_data) values(?, ?, ?)");
pstmt.setString(1, cl.getOwner());
pstmt.setString(2, "");
pstmt.setBytes(3, cl.getCompressedData());
int i = pstmt.executeUpdate();but this didn't work because of Cast Exception - java.lang.ClassCastException: org.apache.tomcat.dbcp.dbcp.DelegatingPreparedStatement cannot be cast to com.mysql.jdbc.PreparedStatement What is the right way to do it? Thanks.
-
Hi, I'm new in Java and have the following task to do: I have some data stored in gzip byte array and I have to insert it into MySQL database. I'm using DBCP (Apache Tomcat 6.0.20) not JDBC. I tried the following code:
PreparedStatement pstmt =(PreparedStatement)con.prepareStatement("insert into test_tb (id, data, compressed_data) values(?, ?, ?)");
pstmt.setString(1, cl.getOwner());
pstmt.setString(2, "");
pstmt.setBytes(3, cl.getCompressedData());
int i = pstmt.executeUpdate();but this didn't work because of Cast Exception - java.lang.ClassCastException: org.apache.tomcat.dbcp.dbcp.DelegatingPreparedStatement cannot be cast to com.mysql.jdbc.PreparedStatement What is the right way to do it? Thanks.
Declare pstmt as java.sql.PreparedStatement, not com.mysql.jdbc.PreparedStatement.