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 : 
// This JDBC code has something missing, and will not run until its added
// Add that missing thing here
import java.sql.*;
import java.util.Scanner;
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");
~~~THERE IS SOME INVISIBLE CODE HERE~~~
} catch (Exception e) {
            System.out.println(e);
        }
    }
}
   


 
 
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 : 
import java.sql.*;
import java.lang.*;
import java.util.Scanner;
 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
//Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection(DB_URL);
System.out.print(conn.isValid(1));
~~~THERE IS SOME INVISIBLE CODE HERE~~~
conn.close();
        } catch (Exception e) {
            System.out.println(e);
        }
    }
}
   


 
 
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 : 
// Fix bugs in the code, DO NOT ADD or DELETE ANY LINE
import java.sql.*;
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");
              conn = DriverManager.getConnection(DB_URL);
              conn.close();
              System.out.print(conn.isClosed());
~~~THERE IS SOME INVISIBLE CODE HERE~~~
conn.close();
        } catch (Exception e) {
            System.out.println(e);
        }
    }
}
   


 
 
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 : 
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);
~~~THERE IS SOME INVISIBLE CODE HERE~~~
}
       catch(Exception e){ System.out.println(e);}  
    }
}
   


 
 
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 : 
import java.sql.*;
import java.lang.*;
public class W11_P5 {
    public static void main(String args[]) throws SQLException {
        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 STUDENTS RENAME TO GRADUATES;";
// Execute the SQL command
stmt.executeUpdate(alter);
~~~THERE IS SOME INVISIBLE CODE HERE~~~
}
       catch(Exception e){ System.out.println(e);}  
    }
}
   


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

netaji gandi Thursday, April 4, 2024

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...