0% found this document useful (0 votes)
4 views1 page

CSV FileToDBTable

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views1 page

CSV FileToDBTable

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

From excel sheet to database table:

===================================

package com.nit.jdbc;
import java.io.FileInputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.util.Scanner;

public class CSVReader {

public static void main(String[] args) {


int k=0;
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con=DriverManager.getConnection
("jdbc:oracle:thin:@localhost:1521:xe","system","oracle");
PreparedStatement ps=con.prepareStatement
("insert into csvdata values(?,?,?,?,?)");
FileInputStream fis=new FileInputStream
("C:\\Users\\DELL\\Downloads\\MOCK_DATA.csv");
Scanner s=new Scanner(fis);
s.nextLine();
while(s.hasNext())
{
String str[]=s.nextLine().split(",");
for(int i=1;i<=5;i++)
{
ps.setString(i, str[i-1]);
}
}
if(k>0)
System.out.println("data inserted.....");
}
catch (Exception e) {

You might also like