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
  datetime   TIMESTAMP   Timestamp
  datetime2(7)   TIMESTAMP   Timestamp
  datetimeoffset(7)   DATETIMEOFFSET
  decimal(18,0)   DECIMAL   BigDecimal
  float   DOUBLE   double   getDouble()
  image   LONGVARBINARY   byte[]   getBytes()
  int   INTEGER   int   getInt()
  money   DECIMAL   BigDecimal
  nchar(10)   NCHAR   String   getNString()
  ntext   LONGNVARCHAR   String   getNString()
  numeric(18,0)   NUMERIC   BigDecimal
  nvarchar(50)   NVARCHAR   String   getNString()
  nvarchar(MAX)   NVARCHAR   String   getNString()
  real   REAL   float   getFloat()
  smalldatetime   TIMESTAMP   Timestamp
  smallint   SMALLINT   short   getShort()
  smallmoney   DECIMAL   BigDecimal
  text   LONGVARCHAR   String   getString()
  time(7)   TIME (1)   Time
  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.