import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
public class Jdbc3
{
public static void main(String[] args)throws ClassNotFoundException
{
// Loading & Register the Type-1 Driver Class(JdbcOdbcDriver). But this line is optional
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
// Establishing the connection
try(Connection con=DriverManager.getConnection("jdbc:odbc:alt","system","manager"))
{
// Creating statement to execute query
Statement st=con.createStatement();
// Executing Query
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String check=null; // to check user want to enter more data or not
do
{
System.out.print("Enter id : ");
int id=Integer.parseInt(br.readLine());
System.out.print("Enter Name : ");
String name=br.readLine();
System.out.println("Enter Salary : ");
float sal=Float.parseFloat(br.readLine());
int rc=st.executeUpdate("insert into emp values("+id+",'"+name+"',"+sal+")");
System.out.println(rc+" row inserted");
System.out.println("Do you insert more? (yes/no)");
check=br.readLine();
}while(!check.equalsIgnoreCase("no"));
System.out.println("----------------End of Application -----------------");
}
catch(SQLException|IOException e) //Multi Catch Block supported in jdk1.7 or higher version
{
e.printStackTrace();
}
}
}
import java.io.IOException;
import java.io.InputStreamReader;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
public class Jdbc3
{
public static void main(String[] args)throws ClassNotFoundException
{
// Loading & Register the Type-1 Driver Class(JdbcOdbcDriver). But this line is optional
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
// Establishing the connection
try(Connection con=DriverManager.getConnection("jdbc:odbc:alt","system","manager"))
{
// Creating statement to execute query
Statement st=con.createStatement();
// Executing Query
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String check=null; // to check user want to enter more data or not
do
{
System.out.print("Enter id : ");
int id=Integer.parseInt(br.readLine());
System.out.print("Enter Name : ");
String name=br.readLine();
System.out.println("Enter Salary : ");
float sal=Float.parseFloat(br.readLine());
int rc=st.executeUpdate("insert into emp values("+id+",'"+name+"',"+sal+")");
System.out.println(rc+" row inserted");
System.out.println("Do you insert more? (yes/no)");
check=br.readLine();
}while(!check.equalsIgnoreCase("no"));
System.out.println("----------------End of Application -----------------");
}
catch(SQLException|IOException e) //Multi Catch Block supported in jdk1.7 or higher version
{
e.printStackTrace();
}
}
}
0 Comment to " Jdbc Program to insert data in 'emp' table in Oracle database using type-1 driver."
Post a Comment