Nptel Programming in Java Week 11 Assignment Answers

Nptel Programming in Java Week 11 Assignment Answers

Searching for the Week 11 answers of the NPTEL “Programming in Java” course? You’re in the right spot! Here, you’ll find reliable and up-to-date solutions to help you complete your Week 11 assignment with confidence.

Nptel Programming in Java Week 11 Assignment Answers

Programming In Java

ABOUT THE COURSE :
With the growth of Information and Communication Technology, there is a need to develop large and complex software. Further, those software should be platform independent, Internet enabled, easy to modify, secure, and robust. To meet this requirement object-oriented paradigm has been developed and based on this paradigm the Java programming language emerges as the best programming environment. Now, Java programming language is being used for mobile programming, Internet programming, and many other applications compatible to distributed systems. This course aims to cover the essential topics of Java programming so that the participants can improve their skills to cope with the current demand of IT industries and solve many problems in their own filed of studies.
INTENDED AUDIENCE :  The undergraduate students from the engineering disciplines namely CSE, IT, EE, ECE, etc. might be interested for this course.

PREREQUISITES :  
This course requires that the students are familiar with programming language such as C/C++ and data structures, algorithms.

INDUSTRY SUPPORT : 
  All IT companies.

COURSE LAYOUT – Click To Know More

Week 1  :  Overview of Object-Oriented Programming and Java
Week 2  :  Java Programming Elements
Week 3  :  Input-Output Handling in Java
Week 4  :  Encapsulation
Week 5  :  Inheritance
Week 6  :  Exception Handling
Week 7  :  Multithreaded Programming
Week 8  :  Java Applets and Servlets
Week 9  :  Java Swing and Abstract Windowing Toolkit (AWT)
Week 10 : Networking with Java
Week 11 :  Java Object Database Connectivity (ODBC)
Week 12 :  Interface and Packages for Software Development
Unlocking the fundamentals of Java programming, the NPTEL Week 11 assignment is designed to introduce learners to the core concepts of this powerful object-oriented language. From understanding Java’s syntax and structure to writing simple programs, this week lays the foundation for a deeper journey into Java development. In this post, we provide clear and concise solutions to the Week 11 assignment, ensuring clarity for beginners while adhering to academic integrity and learning goals. Dive in to reinforce your concepts and validate your approach.
Get All Week Nptel Assignment Answers – Click Here

Nptel Programming in Java Week 11 Assignment Answers

1) What is the full form of JDBC?

a. Java Database Connectivity
b. Java Data Code
c. Java Data Communication
d. Java Development Connectivity

View Answer


2) Fill in the missing code to establish a connection to a MySQL database.

import java.sql.*;

public class JDBCExample {
public static void main(String[] args) {
try {
// Load JDBC Driver
Class.forName(“com.mysql.cj.jdbc.Driver”);

// Establish Connection
Connection connection = // INSERT CODE HERE;

System.out.println(“Connected to the database.”);
connection.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}

What should replace // INSERT CODE HERE?

a. DriverManager.connect(“mysql:localhost:mydb”, “user”, “password”);
b. DriverManager.getConnection(“jdbc:mysql://localhost:3306/mydb”, “user”, “password”);
c. Connection.get(“jdbc:mysql://localhost:3306/mydb”, “user”, “password”);
d. Driver.connect(“jdbc:mysql://localhost:mydb”, “user”, “password”);

View Answer


3) Identify the error and select the corrected statement

import java.sql.*;

public class ResultSetExample {
public static void main(String[] args) throws SQLException {
Connection connection = DriverManager.getConnection(“jdbc:mysql://localhost:3306/mydb”, “user”, “password”);
Statement stmt = connection.createStatement();
ResultSet rs = stmt.execute(“SELECT * FROM users”); // Error
while (rs.next()) {
System.out.println(rs.getString(“username”));
}
connection.close();
}
}

Correct line to replace the error:

a. ResultSet rs = stmt.executeQuery(“SELECT * FROM users”);
b. ResultSet rs = stmt.runQuery(“SELECT * FROM users”);
c. ResultSet rs = stmt.execute(“users SELECT * FROM”);
d. ResultSet rs = stmt.fetch(“SELECT * FROM users”);

View Answer


4) What will the Java program output if the table products contains a column name and three rows: Laptop, Phone, and Tablet?

import java.sql.*;

public class DisplayProducts {
public static void main(String[] args) {
try {
Connection conn = DriverManager.getConnection(“jdbc:mysql://localhost:3306/store”, “root”, “pass”);
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(“SELECT name FROM products”);
while (rs.next()) {
System.out.println(rs.getString(“name”));
}
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}

a. Compilation Error
b. Runtime Error
c. Laptop
Phone
Tablet
d. No Output

View Answer

For Latest Update Join our official channel: Click here to join


5) Complete the following code to insert a new user into a users table.

import java.sql.*;

public class InsertUser {
public static void main(String[] args) {
try {
Connection conn = DriverManager.getConnection(“jdbc:mysql://localhost:3306/mydb”, “root”, “password”);
String query = “INSERT INTO users (username, email) VALUES (?, ?)”;
PreparedStatement pstmt = // INSERT CODE HERE;
pstmt.setString(1, “john doe”);
pstmt.setString(2, “john@example.com”);
pstmt.executeUpdate();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}

What should replace // INSERT CODE HERE?

a. conn.createStatement(query);
b. conn.prepareStatement(query);
c. conn.execute(query);
d. conn.runStatement(query);

View Answer


6) Which of the following SQL operations can be executed using the executeUpdate method in JDBC?

I. INSERT INTO users (id, name) VALUES (1, ‘Alice’);
II. UPDATE users SET name=’Bob’ WHERE id=1;
III. DELETE FROM users WHERE id=1;
IV. SELECT * FROM users;

a. I, II, and III
b. Only I and II
c. Only I
d. I, II, III and IV

View Answer


7) What is the purpose of the DriverManager class in JDBC?

a. To manage database connections.
b. To execute SQL queries.
c. To fetch data from a database.
d. To represent a database record.

View Answer


8) How do you establish a connection to a database using JDBC?

a. By creating an instance of the Connection interface
b. By using the DriverManager.getConnection() method
c. By implementing the Connection interface
d. By extending the Connection class

View Answer

For Latest Update Join our official channel: Click here to join


9) Which method executes a simple query and returns a single Result Set object?

a. executeQuery()
b. executeUpdate()
c. execute()
d. run()

View Answer


10) Which package in Java contains the classes and interfaces for JDBC?

a. java.sql
b. java.io
c. java.db
d. java.net

View Answer

Nptel Programming in Java Week 12 Assignment Answers – Click Here