I don't have any idea about your database but you need to define the method to insert your table id and you need to create connection class for your oracle database
Also you need to mange your table id Increment you should create an trigger to increment table id after each insert operation
i will post an method that select the max id from table , you can find oracle trigger to increase sequence in the link below
How to create id with AUTO_INCREMENT on Oracle?
first we need to create method that return max id from your table
public static int getMaxBookID(Connection connection){
int id=0;
String sql = "SELECT NVL(MAX(ID),0)+1 FROM BOOK ";
try{
PreparedStatement statement = connection.prepareStatement(sql);
if(statement!=null){
try{
ResultSet results = statement.executeQuery();
if(results != null){
try{
if(results.next()){
id = results.getInt(1);
}
}
catch(Exception resultSetException) {resultSetException.printStackTrace();
}
results.close();
}
}
catch(Exception statmentExcption){statmentExcption.printStackTrace();
}
statement.close();
}
} catch (Exception generalException){generalException.printStackTrace();
}
return id;
}
this two methods are used to open and close your connection
private static final String DB_DRIVER = "oracle.jdbc.driver.OracleDriver";
private static final String DB_CONNECTION = "jdbc:oracle:thin:@//host:1526/databasename";
private static final String DB_USER = "username";
private static final String DB_PASSWORD = "passowrd";
public static Connection lockConnection() {
Connection dbConnection = null;
try {
Class.forName(DB_DRIVER);
} catch (ClassNotFoundException e) {
System.out.println(e.getMessage());
}
try {
return DriverManager.getConnection(
DB_CONNECTION, DB_USER, DB_PASSWORD);
} catch (SQLException e) {
System.out.println(e.getMessage());
}
return dbConnection;
}
public static void closeMyConnection(Connection connection) {
try {
connection.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
now You can insert your information into your table
public int AddBook(String name,String auth,String year , String avail){
int id=0;
Connection connection = lockConnection();
boolean ok = false;
String sql = "INSERT INTO BOOKS(ID,NAME, AUTHORS, PUBLISHYEAR, AVAIL)"
+ " VALUES(?,?,?,?,?)";
try{
PreparedStatement statement = connection.prepareStatement(sql);
if(statement!=null){
statement.setInt(1,getMaxBookID(connection));
statement.setString(2,name);
statement.setString(3,auther);
statement.setString(4,year);
statement.setString(5,avail);
try{
int count = statement.executeUpdate();
ok = count == 1;
if(!ok)id=0;
}
catch(Exception statmentExcption){statmentExcption.printStackTrace();statmentExcption.printStackTrace(); return 0 ;
}
statement.close();
}
} catch (Exception generalException){generalException.printStackTrace(); generalException.printStackTrace(); return 0;
}
closeMyConnection(connection);
return id;
}