
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.*;
import java.util.Scanner;
public class New {
private static Connection connection = null;
public Connection getConnection()
{
try {
// Load the JDBC driver
String driverName = "oracle.jdbc.driver.OracleDriver";
Class.forName(driverName);
// Create a connection to the database
String url = "jdbc:oracle:thin:@172.24.137.30:1521:ORA10G" ;
String username = "e545779";
String password = "JdyIixugi";
connection = DriverManager.getConnection(url, username, password);
System.out.println("hiiiiiiiii");
} catch (ClassNotFoundException e) {
// Could not find the database driver
} catch (SQLException e) {
// Could not connect to the database
}
return connection;
}
private New() {
super();
}
public static New empDetails(Connection connection)
{
try
{
String empName;
int sal,deptId;
Scanner sc=new Scanner(System.in);
System.out.println("Enter EmpName");
empName=sc.next();
System.out.println("Enter sal");
sal=sc.nextInt();
System.out.println("Enter deptId");
deptId=sc.nextInt();
Statement st=null;
st=connection.createStatement();
ResultSet rs1=st.executeQuery("insert into employee values(emp_seq.nextVal, '"+empName+"',"+sal+","+deptId+")");
}
catch(SQLException e)
{
e.printStackTrace();
}
return null;
}
public static void main(String[] args) {
New n=new New();
int ch;
System.out.println("Enter ur choice(1.Add details/2.View Details");
Scanner sc=new Scanner(System.in);
ch=sc.nextInt();
switch(ch)
{
case 1:
System.out.println("enter emp details");
connection=n.getConnection();
empDetails(connection);
break;
case 2:
System.out.println("Enter Emp Id:");
break;
default:
System.out.println("no choice");
}
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.