Default mapping datatypes from SQL Server to JDBC types and Java objects and ResultSet methods

In this post I show list of datatypes SQL Server and its equivalent datatypes in JDBC and Java objects with methods of ResultSet object.

In this table You may see default datatypes. It  is very helpfull for Java applications get data from SQL Server database by jDBC driver and set them into another place.

  SQL Server datatype   JDBC,    JAVA >=’6.0′   Java datatype   ResultSet method
  bigint   BIGINT   long   getLong()
  binary   BINARY   byte[]   getBytes()
  bit   BIT   boolean   getBoolean()
  char(10)   CHAR   String   getString()
  date   DATE   Date
(java.sql)
  getDate()
  datetime   TIMESTAMP   Timestamp
(java.sql)
  getTimestamp()
  datetime2(7)   TIMESTAMP   Timestamp
(java.sql)
  getTimestamp()
  datetimeoffset(7)   DATETIMEOFFSET
(microsoft.sql.Types)
 DateTimeOffset
(microsoft.sql)
  getDateTimeOffset()
getString()
  decimal(18,0)   DECIMAL   BigDecimal
(java.math)
  getBigDecimal()
  float   DOUBLE   double   getDouble()
  image   LONGVARBINARY   byte[]   getBytes()
  int   INTEGER   int   getInt()
  money   DECIMAL   BigDecimal
(java.math)
  getBigDecimal()
  nchar(10)   NCHAR   String   getNString()
  ntext   LONGNVARCHAR   String   getNString()
  numeric(18,0)   NUMERIC   BigDecimal
(java.math)
  getBigDecimal()
  nvarchar(50)   NVARCHAR   String   getNString()
  nvarchar(MAX)   NVARCHAR   String   getNString()
  real   REAL   float   getFloat()
  smalldatetime   TIMESTAMP   Timestamp
(java.sql)
  getTimestamp()
  smallint   SMALLINT   short   getShort()
  smallmoney   DECIMAL   BigDecimal
(java.math)
  getBigDecimal()
  text   LONGVARCHAR   String   getString()
  time(7)   TIME (1)   Time
(java.sql)
  getTime()
  timestamp   LONGVARCHAR   byte[]   getBytes()
  tinyint   TINYINT   short   getShort()
  uniqueidentifier   CHAR   String   getString()
  varbinary(50)   VARBINARY   byte[]   getBytes()
  varbinary(MAX)   VARBINARY   byte[]   getBytes()
  varchar(50)   VARCHAR   String    getString()
  varchar(MAX)   VARCHAR   String    getString()
  xml   LONGNVARCHAR   String    getString()

 

Leave a Reply

Your email address will not be published.

Time limit is exhausted. Please reload CAPTCHA.