NPTEL Programming In Java Week 11 Programming Assignment Answers Solution | 2026 July | Swayam

 W11 Programming Assignments 1

Due date on 2026-10-08, 23:59 IST

Your last recorded submission was on 2026-09-26, 16:08 IST.

Q.

The following code needs some package to work properly.
Write appropriate code to
  • import the required package(s) in order to make the program compile and execute successfully.
(Ignore the hidden code.)

Complete Program

Java
//Import required packages
// Hint: USE static import
import java.sql.*;
import java.lang.*;
import static java.sql.DriverManager.*;

public class W11_P1 {
    public static void main(String args[]) {
        try {
            Connection conn = null;
            Statement stmt = null;
            String DB_URL = "jdbc:sqlite:/tempfs/db";
            System.setProperty("org.sqlite.tmpdir", "/tempfs");
            
            // Connection using static import method from DriverManager
            conn = getConnection(DB_URL);
            System.out.println(conn.isValid(1));
            conn.close();
        } catch (Exception e) {
            System.out.println(e);
        }
    }
}
You may submit any number of times before the due date. The final submission will be considered for grading.

This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program, your assignment will not be graded and you will not see your score after the deadline.

Evaluation Results

CompilationSuccessful|Public Test Cases: 1/1 Passed

Note: These tests may not be considered while scoring.

Public Test Cases

Test Case
Input
Expected Output
Output
Status
Test Case 1

0

true
true
-


W11 Programming Assignments 2

Due date on 2026-10-08, 23:59 IST

Your last recorded submission was on 2026-09-26, 16:11 IST.

Q.

Write the JDBC codes needed to create a Connection interface using the DriverManager class and the variable DB_URL. Check whether the connection is successful using 'isValid(timeout)'method to generate the output, which is either 'true' or 'false'.

Note the following points carefully:
  • Name the connection object as conn only.
  • Use timeout value as 1.
  • Ignore the hidden code.

Complete Program

Java
import java.sql.*;
import java.util.Scanner;

public class W11_P2 {
    public static void main(String args[]) {
        try {
            Connection conn = null;
            Statement stmt = null;
            String DB_URL = "jdbc:sqlite:/tempfs/db";
            System.setProperty("org.sqlite.tmpdir", "/tempfs");

            // Open a connection
            conn = DriverManager.getConnection(DB_URL);
            System.out.print(conn.isValid(1));

            conn.close();
        } catch (Exception e) {
            System.out.println(e);
        }
    }
}
You may submit any number of times before the due date. The final submission will be considered for grading.

This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program, your assignment will not be graded and you will not see your score after the deadline.

Evaluation Results

CompilationSuccessful|Public Test Cases: 1/1 Passed

Note: These tests may not be considered while scoring.

Public Test Cases

Test Case
Input
Expected Output
Output
Status
Test Case 1

0

true
true
-


W11 Programming Assignments 3

Due date on 2026-10-08, 23:59 IST

Your last recorded submission was on 2026-09-26, 16:12 IST.

Q.

Due to some mistakes in the below code, the code is not compiled/executable.
Modify and debug the JDBC code to make it execute successfully.

Complete Program

Java
// Fix bugs in the code, DO NOT ADD or DELETE ANY LINE
import java.sql.*;  // All sql classes are imported
import java.lang.*; // Semicolon is added
import java.util.Scanner;
public class W11_P3 {
    public static void main(String args[]) {
        try {
            Connection conn = null;
            Statement stmt = null;
            String DB_URL = "jdbc:sqlite:/tempfs/db";
            System.setProperty("org.sqlite.tmpdir", "/tempfs");
            // Connection object is created
            conn = DriverManager.getConnection(DB_URL);     // Add this line
            conn.close();                                   // correction here
            System.out.print(conn.isClosed());
            
            // Hidden code completes try-catch block
        } catch (Exception e) {
            System.out.println(e);
        }
    }
}
You may submit any number of times before the due date. The final submission will be considered for grading.

This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program, your assignment will not be graded and you will not see your score after the deadline.

Evaluation Results

CompilationSuccessful|Public Test Cases: 1/1 Passed

Note: These tests may not be considered while scoring.

Public Test Cases

Test Case
Input
Expected Output
Output
Status
Test Case 1

0

true
true
-


W11 Programming Assignments 4

Due date on 2026-10-08, 23:59 IST

Your last recorded submission was on 2026-09-26, 16:14 IST.

Q.

Complete the code segment to create a new table named 'STUDENTS' in SQL database using the following information.

ColumnUIDNameRollAge
TypeIntegerVarchar (45)Varchar (12)Integer

Complete Program

Java
import java.sql.*;
import java.lang.*;

public class W11_P4 {
    public static void main(String args[]) {
        try {
            Connection conn = null;
            Statement stmt = null;
            String DB_URL = "jdbc:sqlite:/tempfs/db";
            System.setProperty("org.sqlite.tmpdir", "/tempfs");
            // Open a connection
            conn = DriverManager.getConnection(DB_URL);
            stmt = conn.createStatement();

            String CREATE_TABLE_SQL="CREATE TABLE STUDENTS (UID INT, Name VARCHAR(45), Roll VARCHAR(12), Age INT);";
            // Execute the statement containing SQL command
            stmt.executeUpdate(CREATE_TABLE_SQL);

        }
        catch(Exception e){ System.out.println(e);}
    }
}

Code Snippet to Paste in the Editor

Java
String CREATE_TABLE_SQL="CREATE TABLE STUDENTS (UID INT, Name VARCHAR(45), Roll VARCHAR(12), Age INT);";
// Execute the statement containing SQL command
stmt.executeUpdate(CREATE_TABLE_SQL);
You may submit any number of times before the due date. The final submission will be considered for grading.

This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program, your assignment will not be graded and you will not see your score after the deadline.

Evaluation Results

CompilationSuccessful|Public Test Cases: 1/1 Passed

Note: These tests may not be considered while scoring.

Public Test Cases

Test Case
Input
Expected Output
Output
Status
Test Case 1

1

No. of columns : 4\n
Column 1 Name: UID\n
Column 1 Type : INT\n
Column 2 Name: Name\n
Column 2 Type : VARCHAR\n
Column 3 Name: Roll\n
Column 3 Type : VARCHAR\n
Column 4 Name: Age\n
Column 5 Type : INT
No. of columns : 4\n
Column 1 Name: UID\n
Column 1 Type : INT\n
Column 2 Name: Name\n
Column 2 Type : VARCHAR\n
Column 3 Name: Roll\n
Column 3 Type : VARCHAR\n
Column 4 Name: Age\n
Column 5 Type : INT
-


W11 Programming Assignments 5

Due date on 2026-10-08, 23:59 IST

Your last recorded submission was on 2026-09-26, 16:16 IST.

Q.

Complete the code segment to rename an already created table named 'STUDENTS' into 'GRADUATES'.

Complete Program

Java
import java.sql.*;
import java.lang.*;

public class W11_P5 {
    public static void main(String args[]) {
        try {
            Connection conn = null;
            Statement stmt = null;
            String DB_URL = "jdbc:sqlite:/tempfs/db";
            System.setProperty("org.sqlite.tmpdir", "/tempfs");
            // Open a connection
            conn = DriverManager.getConnection(DB_URL);
            stmt = conn.createStatement();

            // Write the SQL command to rename a table
            String alter="ALTER TABLE STUDENTS RENAME TO GRADUATES;";
            // Execute the SQL command
            stmt.executeUpdate(alter);

        }    catch(Exception e){ System.out.println(e);}
    }
}

Code Snippet to Paste in the Editor

Java
// Write the SQL command to rename a table
String alter="ALTER TABLE STUDENTS RENAME TO GRADUATES;";
// Execute the SQL command
stmt.executeUpdate(alter);
You may submit any number of times before the due date. The final submission will be considered for grading.

This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program, your assignment will not be graded and you will not see your score after the deadline.

Evaluation Results

CompilationSuccessful|Public Test Cases: 1/1 Passed

Note: These tests may not be considered while scoring.

Public Test Cases

Test Case
Input
Expected Output
Output
Status
Test Case 1

1

TABLE NAME = GRADUATES
TABLE NAME = GRADUATES
-


No comments