[Database] - UPDATE STATISTICS for all SQL Server Databases

July 14, 2018 |


Run update statistics for SQL Server database.
Step 1: Run following the SQL script below:
DECLARE @SQL VARCHAR(1000DECLARE @DB sysname 
DECLARE curDB CURSOR FORWARD_ONLY STATIC FOR 
   SELECT 
[name] 
   
FROM master..sysdatabases
   
WHERE [name] NOT IN ('model''tempdb')
   
ORDER BY [name]
    
OPEN curDB  FETCH NEXT FROM curDB INTO @DB  WHILE @@FETCH_STATUS 
   
BEGIN 
       SELECT 
@SQL 'USE [' @DB +']' CHAR(13) + 'EXEC sp_updatestats' CHAR(13
       
PRINT @SQL 
       
FETCH NEXT FROM curDB INTO @DB 
   
END 
   
CLOSE 
curDB  DEALLOCATE 
curDB


Results:
USE [Dummy] EXEC sp_UpdateStats
USE [master] EXEC sp_UpdateStats
USE [msdb] EXEC sp_UpdateStats
USE [MSSQLTips] EXEC sp_UpdateStats
USE [MSSQLTips_DUPE] EXEC sp_UpdateStats
USE [Northwind] EXEC sp_UpdateStats
USE [Sitka] EXEC sp_UpdateStats
USE [Utility] EXEC 
sp_UpdateStats


Step 2: Copy and run database which you want to update statistics.

If you want to know how to use run update statistic alse problem and solution, please access to link below:

The article use source from: https://www.mssqltips.com/sqlservertip/1606/execute-update-statistics-for-all-sql-server-databases/

Read more…

[Java] - Encode/Decode Base64 String

July 14, 2018 |


I. Encode image to base64 string
 Convert an image to base64 string so that send via SOAP Message, RESTFul or save to database.

Codes:
 public String encodeToString(BufferedImage image, String type) {
        String imageString = null;
        ByteArrayOutputStream bos = new ByteArrayOutputStream();

        try {
            ImageIO.write(image, type, bos);
            byte[] imageBytes = bos.toByteArray();

            BASE64Encoder encoder = new BASE64Encoder();
            imageString = encoder.encode(imageBytes);

            //imageString = Base64.getEncoder().encodeToString(imageBytes);

            bos.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return imageString;
    }


II. Decode base64 string to image
 Decode base64 sring to image so that display on UI or other.

Codes:
 private BufferedImage decodeToImage(String imageString) {
        BufferedImage image = null;
        byte[] imageByte;
        try {
            BASE64Decoder decoder = new BASE64Decoder();
            imageByte = decoder.decodeBuffer(imageString);

            //imageByte = Base64.getDecoder().decode(imageString);
            ByteArrayInputStream bis = new ByteArrayInputStream(imageByte);
            image = ImageIO.read(bis);
            bis.close();
        } catch (Exception e) {
            LOGGER.err(e.toString());
            return null;
        }
      
        return image;
    }


Updating...
Read more…