Programming In Java Week 10: Programming Assignments Jan-Jun 2022

 NPTEL PROGRAMMING ASSIGNMENTS

Week 10 : Programming Assignment 1

Due Date of Submission 2022-04-07, 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.


 

 


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");
              conn = DriverManager.getConnection(DB_URL);
              System.out.print(conn.isValid(1));
              conn.close();
        }
       catch(Exception e){ System.out.println(e);}  
    }
}







Week 10 : Programming Assignment 2

Due Date of Submission 2022-04-07, 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.



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");

 

 


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





Week 10 : Programming Assignment 3

Due Date of Submission 2022-04-07, 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.

 

 







Week 10 : Programming Assignment 4

Due Date of Submission 2022-04-07, 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



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");
              conn = DriverManager.getConnection(DB_URL);
              stmt = conn.createStatement();


 

 

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





Week 10 : Programming Assignment 5

Due Date of Submission 2022-04-07, 23:59 IST

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



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");

              conn = DriverManager.getConnection(DB_URL);

              stmt = conn.createStatement();


 

 


Post a Comment (0)
Previous Post Next Post