Answer to Question #270130 in Java | JSP | JSF for Tarurendra Kushwah

Question #270130

Write a program in Java that enters student details (Roll No, Name etc) and retrieves information.



Use oracle as a database and write the application in JDBC.

1
Expert's answer
2021-11-24T00:41:13-0500
import java.sql.*;

public class Main {
    public static void main(String[] args) {
        try (Connection connection = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:mydb",
                "username", "password")) {
            Statement statement = connection.createStatement();
            statement.executeUpdate("INSERT INTO student VALUES (1, 'Bob', 20)");
            statement.executeUpdate("INSERT INTO student VALUES (2, 'Adam', 18)");
            statement.executeUpdate("INSERT INTO student VALUES (3, 'Thomas', 21)");

            ResultSet select = statement.executeQuery("SELECT * FROM student");
            while (select.next()) {
                System.out.printf("Roll number: %d Name: %s Age: %d\n", select.getInt("rollNumber"),
                        select.getString("name"), select.getInt("age"));
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS