Posts

How to upload csv file into MySQL Database Example

Comma-Seperated-Value(CSV) file is a common file that used by most developers to extract data from database. Today i want to show how to upload or insert CSV file into database MySQL directly without need to read line by line in the CSV file. Let say this is the example of CSV file CSV File Content,Example 1 NO;DATE;TIME;ACCNO;STATUS 1;20131211;100856;12345;ACTIVE 2;20131211;095625;25896;NOT ACTIVE CSV File Content, Example 2 "NO";"DATE";"TIME";"ACCNO";"STATUS" "1";"20131211";"100856";"12345";"ACTIVE" "2";"20131211";"095625";"25896";"NOT ACTIVE" The above csv file are two example of csv files content. Lets start learn how to upload this file into MySQL Database. MySQL have a powerful sql statement to read this file and insert into database as batch. This statement is the fastest way to insert into database. You can read more about LOAD

JDBC PrepareStatement Insert Data As A Batch - JAVA(MySQL)

In this tutorial i will show example to add data into database MySQL as a batch. The idea is to prepare the batch data to pump into database one time only. This approach is a best solution if you more than 1 records to insert into database. If you insert one by one data to database, the process will be slow, hence batch process will inprove application performance. Take a look on the example and try it by your self. =) The Batch Update Example public void insertAsBatch()     {         String strsql = "INSERT INTO sysusers(UserID,UserEmail,Password) VALUES(?,?,?)";         PreparedStatement prepStatement = null;         Connection dbConn = TestConnectionDb();         int batchSize = 100;//set the batch size to commit intodatabase(optional)         int IndexCounterBatch = 0;         try         {                        dbConn.setAutoCommit(false);             prepStatement = dbConn.prepareStatement(strsql);             for(int i=0; i < 200;i++)             {                 

JDBC Prepare Statement to select data from database MySQL

In this tutorial i will show how to read data from database MySQl using PrepareStatement. You can read in this tutorial to create connection to database MySQL Full Example :  public void readDatabase()     {         String strsql = "SELECT * FROM sysusers WHERE UserID=?";         PreparedStatement prepStatement = null;         Connection dbConn = TestConnectionDb();         String uid = "";         String uemail = "";         try         {                        prepStatement = dbConn.prepareStatement(strsql);             prepStatement.setString(1, "developersnote");             ResultSet rs = prepStatement.executeQuery();             while (rs.next()) {                 uid = rs.getString("UserID");                 uemail = rs.getString("UserEmail");             }             System.out.println(uid);             System.out.println(uemail);         }         catch (SQLException se) {             System.out.println(se.getMessage

JDBC create connection or test connection to MySQL database

Here is a example how to make connection to database MySQL using ( J ava D ata B ase C onnectivity)JDBC driver. In your project you must include MySQL JDBC Driver, otherwise you will get error "MySQL JDBC Driver not found" . This is the full Method to check or test connection to MySQL Database using JDBC driver. The TestConnectionDb Method public static boolean TestConnectionDb() {                 String DbConnectionString ="jdbc:mysql://localhost:3306/";         //or you can directly connecto to your database schema like this :         //String DbConnectionString ="jdbc:mysql://localhost:3306/<schema name>";                 String User = "root";         String Password = "P@ssw0rd";                 Connection connection = null;         try {                        Class.forName("com.mysql.jdbc.Driver");             connection = DriverManager.getConnection(DbConnectionString, User, Password);         } catch (ClassNotFou

Encrypt And Decrypt Example in C#

It is not enough to show example only in Java, in this tutorial i will show how to do encrypt and decrypt function in C#. You can read about the same example but in Java language Encrypt And Decrypt Example in JAVA In C#, the process for encrypt and decrypt will using MD5CryptoServiceProvider class from System.Security.Cryptography namespace. Read more about this namespace here Example Encrypt in C#    public string encrypt(string toEncrypt, bool useHashing)         {             byte[] keyArray;             byte[] toEncryptArray = UTF8Encoding.UTF8.GetBytes(toEncrypt);             string key = "developersnotedotcom";             if (useHashing)             {                 MD5CryptoServiceProvider hashmd5 = new MD5CryptoServiceProvider();                 keyArray = hashmd5.ComputeHash(UTF8Encoding.UTF8.GetBytes(key));                 hashmd5.Clear();             }             else                 keyArray = UTF8Encoding.UTF8.GetBytes(key);             TripleDESCrypto

Encrypt And Decrypt Example in JAVA

Security is the first concern when you develope application what have sensitive data such as account number, passport number , etc . Today i want to show example how to do simple encrypt and decrypt method in JAVA. In this tutorial i will use 3rd party library, you can download the library by the following link :  Common-Codecs-1.8 The import library : import org.apache.commons.codec.binary.Base64; import java.io.*; import java.security.InvalidAlgorithmParameterException; import java.security.InvalidKeyException; import javax.swing.JOptionPane; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import javax.crypto.BadPaddingException; import javax.crypto.Cipher; import javax.crypto.IllegalBlockSizeException; import javax.crypto.NoSuchPaddingException; import javax.crypto.spec.IvParameterSpec; import javax.crypto.spec.SecretKeySpec; The SharedVector   private static byte[] sharedvector = {     0x01, 0x02, 0x03, 0x05, 0x07, 0x0B, 0x0D, 0x11     }; The Encr

SqlClient Read Data in database using SqlDataReader - C#

This tutorial show how to read database using SqlDataReader in database using SqlClient driver to connect to database. Read here to read data in database and pass to DataTable Requirement in this tutorial are : using System.Data.SqlClient; using System.Data; The Example Read Data using SqlDataReader :             DataSet dataSetTable = new DataSet();             SqlConnection dbConn = new SqlConnection("<connection string>");             SqlCommand dbComm = new SqlCommand("<sql statement or procedure name>", dbConn);             SqlDataReader dbReader;             //set command type is procedure if you are using store procedure             //else remove this line             dbComm.CommandType = CommandType.StoredProcedure;             try             {                                dbConn.Open();                 dbReader = dbComm.ExecuteReader();                 if (dbReader.HasRows) //check if reader have any row                 {