title: Inserting unsigned 64-bit number into BigInt MySQL column using Java and JDBC
body: <p>I searched for answer to this question and only found vague answers. Here is the problem:
  I have a sample table in MySQL:
  mytable
  time Timestamp
  data BigInt(20) unsigned</p>
  
  <p>Data field is chosen so that it can take in 2^64 max value: 18446744073709551616 (20 digits and hence BigInt(20)).</p>
  
  <p>I have a csv file which contains unsigned 64-bit integers.</p>
  
  <p>Now I am using Java and JDBC to insert this data and running into issues because Java does not have unsigned long. So I tried just passing string - but it fails.</p>
  
  <pre><code>st = conn.prepareStatement("INSERT INTO pawan_table (mytime, data) VALUES(?, ?)");
  st.setTimestamp(1, new Timestamp(86400000+i*1000));
  st.setString(2, "18446744073709551616");
  st.execute();
  </code></pre>
  
  <p>I also tried BigInteger class in Java - but JDBC does not have a method which takes that type. I can only convert BigInteger to "long" which is signed and that is not what I want. For example:</p>
  
  <pre><code>BigInteger bi = new BigInteger(string_from_csv_file);
  st.setLong(2, bi.longValue());
  </code></pre>
  
  <p>Interesting thing is that MySQL Workbench can insert this data - but it is written in c#! and I need to write my code in Java! </p>
  
  <p>How do Java programmers insert unsigned 64-bit number in MySQL BigInt(20) column?</p>