Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Java
  4. inserting byte array into mysql DB

inserting byte array into mysql DB

Scheduled Pinned Locked Moved Java
databasequestionjavaapachemysql
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    Evgeni57
    wrote on last edited by
    #1

    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.

    D 1 Reply Last reply
    0
    • E Evgeni57

      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.

      D Offline
      D Offline
      David Skelly
      wrote on last edited by
      #2

      Declare pstmt as java.sql.PreparedStatement, not com.mysql.jdbc.PreparedStatement.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups