title: How to insert into SQL Server decimal column?
body: <p>I'm using the MS JDBC driver for SQL Server, and trying to insert values into a decimal(18,5) column.  The docs say that decimal columns map to BigDecimal, so I'm trying to do this:</p>
  
  <pre><code>PreparedStatement ps = conn.prepareStatement("INSERT INTO [dbo].[AllTypesTable] ([decimal18_0Col]) VALUES (?)");
  ps.setObject(1, new BigDecimal(3.14));
  ps.execute();
  </code></pre>
  
  <p>On the call to execute(), I get this error:</p>
  
  <p>com.microsoft.sqlserver.jdbc.SQLServerException: Error converting data type nvarchar to decimal.</p>
  
  <p>The driver does seem to be happy with doubles, so I can do this:</p>
  
  <pre><code>ps.setObject(1, 3.14);
  </code></pre>
  
  <p>How can I do an insert if I need the extra precision BigDecimal gives me?</p>
  
  <p>Update:  Of course I don't have to worry about this if I'm going to insert 3.14.  What if I want to insert a value that actually needs decimal precision?  Something with 30 decimal places, for example?</p>