title: How do I use Java to read a .csv file and insert its data into SQL Server?
body: <p>I am very new to Java. I have a task with two steps.</p>
  
  <ol>
  <li>I want to read all data from a <code>.csv</code> file.</li>
  <li>After reading that data I have to put it into a SQL Server database.</li>
  </ol>
  
  <p>I have done step one. I'm able to read the <code>.csv</code> file data, but I don't know that how to insert it into a database.</p>
  
  <p>Here's my code for fetching the <code>.csv</code> file data:</p>
  
  <pre><code>import java.io.BufferedReader;  
  import java.io.FileNotFoundException;  
  import java.io.FileReader;  
  import java.io.IOException;  
  import java.util.StringTokenizer;  
  
  
  public class DBcvsdataextractor {  
  
      /** 
       * @param args 
      */  
      public static void main(String[] args) { 
          // TODO Auto-generated method stub  
  
          String fileName="D:/USPresident Wikipedia URLs Thumbs HS.csv";  
  
          try {    
          BufferedReader br = new BufferedReader( new FileReader(fileName));    
              StringTokenizer st = null;    
              int lineNumber = 0, tokenNumber = 0;    
  
              while( (fileName = br.readLine()) != null)    
              {    
  
                  if(lineNumber++ == 0)  
                     continue;                  
  
                  //break comma separated line using ","    
                  st = new StringTokenizer(fileName, ",");    
  
                  while(st.hasMoreTokens())    
                  {    
                      //display csv values    
                      tokenNumber++;    
                      System.out.print(st.nextToken() + '\t'); 
                  }    
  
                  //new line    
                  System.out.println(" ");    
  
                  //reset token number    
                  tokenNumber = 0;    
  
              }    
          } catch (FileNotFoundException e) {    
              // TODO Auto-generated catch block    
              e.printStackTrace();    
          } catch (IOException e) {    
              // TODO Auto-generated catch block    
              e.printStackTrace();    
          }
      }
  }
  </code></pre>
  
  <p>Now, how do I insert that data into SQL Server?</p>