PreparedStatement pstmt = connection. Try (CSVReader reader = new CSVReader(readerstream, ',') Ĭonnection connection = DBConnection.getConnection() ) Reader readerstream = new InputStreamReader(new FileInputStream("D:\\file.csv"), "Unicode") Private static void readCsv() throws UnsupportedEncodingException, FileNotFoundException Public static void main(String args) throws UnsupportedEncodingException, FileNotFoundException Import java.io.UnsupportedEncodingException You can customize below class to insert data into sql server.įile ImportCsv.java package I know the approach of constructing your query while reading the CSV file would be possible as well if you want to go for one big INSERT statement, but separating the INSERT from the reading of the CSV file has the big advantage you can replace your own CSV parser later on by a standard one without too much trouble. Select Azure Blob Storage from the gallery, and then select Continue. Select + Create new connection to add a connection. On the Source data store page, complete the following steps: a. In that case you could construct an indiviual INSERT statement while reading the CSV file, and submit it to the DB after each time a row has been read. On the Properties page of the Copy Data tool, choose Built-in copy task under Task type, then select Next. If you would opt for the last option, it is not even necessary to use those ArrayList instances. Once the file is read, you can loop over those ArrayList instances again to construct one big INSERT statement for all data, or one INSERT statement for each row you encountered in the CSV file.You could for example use an ArrayList for each column in the CSV file, and populate those while reading the CSV file Your CSVReader will have the schema for the data, which will indicate the types of. In your case you just need GetFile -> PutDatabaseRecord. Instead of printing out each 'CSV-file value', you will have to store them. PutDatabaseRecord allows you to put multiple records from one flow file into a database at a time, without requiring the user to convert to SQL (you can use PutSQL for the latter, but it is less efficient).If you really want to do this with Java, and really want to write your own CSV parser as you currently did, you can Now, how do I insert that data into SQL Server? While( (fileName = br.readLine()) != null) String fileName="D:/USPresident Wikipedia URLs Thumbs HS.csv" īufferedReader br = new BufferedReader( new FileReader(fileName)) csv file data: import java.io.BufferedReader csv file data, but I don't know that how to insert it into a database. After reading that data I have to put it into a SQL Server database.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |