NPTEL Programming in Java Programming Assignment 10 Oct-2023 Week 10

 

Week 10 : Programming Assignment 1

Due on 2023-10-05, 23:59 IST
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.
Select the Language for this assignment. 
File name for this program : 
// Import required packages
import java.sql.*;
import java.lang.*;
public class Question101 {
    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");
              
              // JDBC Codes in the hidden section
 
              // Open a connection
              conn = DriverManager.getConnection(DB_URL);
              System.out.print(conn.isValid(1));
              conn.close();
 
// JDBC Codes in the visible section
 
        }
       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.
   


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




Week 10 : Programming Assignment 2

Due on 2023-10-05, 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:
1. Name the connection object as 'conn' only.
2. Use timeout value as 1.

Your last recorded submission was on 2023-09-26, 17:38 IST
Select the Language for this assignment. 
File name for this program : 
import java.sql.*;
import java.lang.*;
import java.util.Scanner;
public class Question102 {
    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));
// Private test case 
                Scanner sc = new Scanner(System.in);
                int s=sc.nextInt();
                if(s==1){
                    conn.close();
                    System.out.print(conn.isValid(1));
                }
}
       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.
   


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





Private Test cases used for EvaluationStatus
Test Case 1
Passed




Week 10 : Programming Assignment 3

Due on 2023-10-05, 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.
Select the Language for this assignment. 
File name for this program : 
import java.sql.*;  // All sql classes are imported
import java.lang.*; // Semicolon is added
import java.util.Scanner;
public class Question103 {
    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);
              conn.close();
              System.out.print(conn.isClosed());
       }
       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.
   


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


Week 10 : Programming Assignment 4

Due on 2023-10-05, 23:59 IST

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

Column

UID

First_Name

Last_Name

Age

Type

Integer

Varchar (45)

Varchar (45)

Integer


Select the Language for this assignment. 
File name for this program : 
import java.sql.*;
import java.lang.*;
public class CreateTable {
    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();
// The statement containing SQL command to create table "players"
String CREATE_TABLE_SQL="CREATE TABLE players (UID INT, First_Name VARCHAR(45), Last_Name VARCHAR(45), Age INT);";
// Execute the statement containing SQL command
stmt.executeUpdate(CREATE_TABLE_SQL);
~~~THERE IS SOME INVISIBLE CODE HERE~~~
}
       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.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
NA
No. of columns : 4\n
Column 1 Name: UID\n
Column 1 Type : INT\n
Column 2 Name: First_Name\n
Column 2 Type : VARCHAR\n
Column 3 Name: Last_Name\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: First_Name\n
Column 2 Type : VARCHAR\n
Column 3 Name: Last_Name\n
Column 3 Type : VARCHAR\n
Column 4 Name: Age\n
Column 5 Type : INT\n
Passed after ignoring Presentation Error




Week 10 : Programming Assignment 5

Due on 2023-10-05, 23:59 IST

Complete the code segment to rename an already created table named ‘PLAYERS’ into ‘SPORTS’.

Select the Language for this assignment. 
File name for this program : 
import java.sql.*;
import java.lang.*;
public class RenameTable {
    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();
~~~THERE IS SOME INVISIBLE CODE HERE~~~
// Write the SQL command to rename a table
String alter="ALTER TABLE players RENAME TO sports;";
 
// Execute the SQL command
stmt.executeUpdate(alter);
~~~THERE IS SOME INVISIBLE CODE HERE~~~
}
       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.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
NA
No. of columns : 4\n
Column 1 Name: UID\n
Column 1 Type : INT\n
Column 2 Name: First_Name\n
Column 2 Type : VARCHAR\n
Column 3 Name: Last_Name\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: First_Name\n
Column 2 Type : VARCHAR\n
Column 3 Name: Last_Name\n
Column 3 Type : VARCHAR\n
Column 4 Name: Age\n
Column 5 Type : INT\n
Passed after ignoring Presentation Error


No comments

File Uploading in PHP

  File Uploading in PHP PHP allow you to upload any type of a file i.e. image, binary or text files.etc..,PHP has one in built global variab...