0% found this document useful (0 votes)
9 views2 pages

Program Sol

The document contains two Java programs for interacting with an Oracle database. Program01 allows users to update or insert data into a 'csvdata' table based on user input, while Program02 reads data from a CSV file and inserts it into the same table. Both programs utilize JDBC for database connectivity and include exception handling for error management.
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)
9 views2 pages

Program Sol

The document contains two Java programs for interacting with an Oracle database. Program01 allows users to update or insert data into a 'csvdata' table based on user input, while Program02 reads data from a CSV file and inserts it into the same table. Both programs utilize JDBC for database connectivity and include exception handling for error management.
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

Program01:

==========
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class CSVFileReader {

public static void main(String[] args) throws SQLException {


Connection con=null;
try {
[Link]("[Link]");
con=[Link]

("jdbc:oracle:thin:@localhost:1521:xe","system","oracle");
PreparedStatement ps1=[Link]
("insert into csvdata values(?,?,?,?,?)");
PreparedStatement ps2=[Link]
("update csvdata set id=? where id=?");
[Link](false);
Scanner s=new Scanner([Link]);
[Link]("[Link]\[Link]");
int choice=[Link]();
switch(choice)
{
case 1:
[Link](1, 13);
[Link](2, 1);//1=====2
[Link]();
[Link]("updated...");

case 2:[Link](1, 22);


[Link](2, "asdf");
[Link](3, "qqqq");
[Link](4, "A@[Link]");
[Link](5, "Male");
[Link]();
[Link]();
[Link]("Inserted...");
}

}
catch (Exception e) {
[Link]("Exception raised...");
[Link]();
}
}

Program02:
===========

package [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class CSVReader {

public static void main(String[] args) {


int k=0;
try {
[Link]("[Link]");
Connection con=[Link]

("jdbc:oracle:thin:@localhost:1521:xe","system","oracle");
PreparedStatement ps=[Link]
("insert into csvdata values(?,?,?,?,?)");
FileInputStream fis=new FileInputStream
("C:\\Users\\DELL\\Downloads\\MOCK_DATA.csv");
Scanner s=new Scanner(fis);
[Link]();
while([Link]())
{
String str[]=[Link]().split(",");
for(int i=1;i<=5;i++)
{
[Link](i, str[i-1]);
}

k=[Link]();
}
[Link]("k="+k);
if(k>0)
[Link]("data inserted.....");
}
catch (Exception e) {

You might also like