Home

Learn Programming & Prepare for NPTEL Exams... Swayam Solver is your one-stop destination for NPTEL exam preparation.

NPTEL Programming in Java Jan 2024 Week 11

 


Week 11 : Programming Assignment 1

Due on 2024-04-11, 23:59 IST
The following code is missing some information needed to run the code.
Add whatever is missing and make the code runnable.
(Ignore the statements ~~~THERE IS SOME INVISIBLE CODE HERE~~~)
Your last recorded submission was on 2024-03-30, 17:16 IST
Select the Language for this assignment. 
File name for this program : 
1
// This JDBC code has something missing, and will not run until its added
2
// Add that missing thing here
3
import java.sql.*;
0
import java.util.Scanner;
1
public class W11_P1 {
2
    public static void main(String args[]) {
3
        try {
4
            Connection conn = null;
5
            Statement stmt = null;
6
            String DB_URL = "jdbc:sqlite:/tempfs/db";
7
            System.setProperty("org.sqlite.tmpdir", "/tempfs");
0
~~~THERE IS SOME INVISIBLE CODE HERE~~~
0
} catch (Exception e) {
1
            System.out.println(e);
2
        }
3
    }
4
}
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.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
0
true
true
Passed




Week 11 : Programming Assignment 2

Due on 2024-04-11, 23:59 IST

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 
'isAlive(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.

Your last recorded submission was on 2024-03-30, 17:26 IST
Select the Language for this assignment. 
File name for this program : 
1
import java.sql.*;
2
import java.lang.*;
3
import java.util.Scanner;
4
 class W11_P2 {
5
    public static void main(String args[]) {
6
        try {
7
              Connection conn = null;
8
              Statement stmt = null;
9
              String DB_URL = "jdbc:sqlite:/tempfs/db";
10
              System.setProperty("org.sqlite.tmpdir", "/tempfs");
11
// Open a connection
12
//Class.forName("com.mysql.jdbc.Driver");
13
conn = DriverManager.getConnection(DB_URL);
14
System.out.print(conn.isValid(1));
0
~~~THERE IS SOME INVISIBLE CODE HERE~~~
0
conn.close();
1
        } catch (Exception e) {
2
            System.out.println(e);
3
        }
4
    }
5
}
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.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
0
true
true
Passed



Week 11 : Programming Assignment 3

Due on 2024-04-11, 23:59 IST

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.

Your last recorded submission was on 2024-03-30, 17:29 IST
Select the Language for this assignment. 
File name for this program : 
1
// Fix bugs in the code, DO NOT ADD or DELETE ANY LINE
2
import java.sql.*;
3
import java.util.Scanner;
4
5
public class W11_P3 {
6
    public static void main(String args[]) {
7
        try {
8
              Connection conn = null;
9
              Statement stmt = null;
10
              String DB_URL = "jdbc:sqlite:/tempfs/db";
11
              System.setProperty("org.sqlite.tmpdir", "/tempfs");
12
              conn = DriverManager.getConnection(DB_URL);
13
              conn.close();
14
              System.out.print(conn.isClosed());
0
~~~THERE IS SOME INVISIBLE CODE HERE~~~
0
conn.close();
1
        } catch (Exception e) {
2
            System.out.println(e);
3
        }
4
    }
5
}
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.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
0
true
true
Passed



Week 11 : Programming Assignment 4

Due on 2024-04-11, 23:59 IST

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

Column

UID

Name

Roll

Age

Type

Integer

Varchar (45)

Varchar (12)

Integer

 

Your last recorded submission was on 2024-03-30, 17:40 IST
Select the Language for this assignment. 
File name for this program : 
1
import java.sql.*;
2
import java.lang.*;
3
public class W11_P4 {
4
    public static void main(String args[]) {
5
        try {
6
              Connection conn = null;
7
              Statement stmt = null;
8
              String DB_URL = "jdbc:sqlite:/tempfs/db";
9
              System.setProperty("org.sqlite.tmpdir", "/tempfs");
10
            
11
              // Open a connection
12
              conn = DriverManager.getConnection(DB_URL);
13
              stmt = conn.createStatement();
14
String CREATE_TABLE_SQL="CREATE TABLE STUDENTS (UID INT, Name VARCHAR(45), Roll VARCHAR(12), Age INT);";
15
// Execute the statement containing SQL command
16
stmt.executeUpdate(CREATE_TABLE_SQL);
0
~~~THERE IS SOME INVISIBLE CODE HERE~~~
0
}
1
       catch(Exception e){ System.out.println(e);}  
2
    }
3
}
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.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
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
Passed


 

 

 

Week 11 : Programming Assignment 5

Due on 2024-04-11, 23:59 IST

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

Your last recorded submission was on 2024-03-30, 17:42 IST
Select the Language for this assignment. 
File name for this program : 
1
import java.sql.*;
2
import java.lang.*;
3
public class W11_P5 {
4
    public static void main(String args[]) throws SQLException {
5
        try {
6
              Connection conn = null;
7
              Statement stmt = null;
8
              String DB_URL = "jdbc:sqlite:/tempfs/db";
9
              System.setProperty("org.sqlite.tmpdir", "/tempfs");
10
            
11
              // Open a connection
12
              conn = DriverManager.getConnection(DB_URL);
13
              stmt = conn.createStatement();
14
~~~THERE IS SOME INVISIBLE CODE HERE~~~
15
// Write the SQL command to rename a table
16
String alter="ALTER TABLE STUDENTS RENAME TO GRADUATES;";
17
// Execute the SQL command
18
stmt.executeUpdate(alter);
0
~~~THERE IS SOME INVISIBLE CODE HERE~~~
0
}
1
       catch(Exception e){ System.out.println(e);}  
2
    }
3
}
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.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
1
TABLE NAME = GRADUATES
TABLE NAME = GRADUATES
Passed


 

No comments:

Post a Comment

Keep your comments reader friendly. Be civil and respectful. No self-promotion or spam. Stick to the topic. Questions welcome.