NPTEL PROGRAMMING ASSIGNMENTS
Programming In Java
Due Date of Submissi on 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 .
--Solution --
Copy text
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);}
}
}
Due Date of Submissi on 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");
--Solution --
Copy text
}
catch (Exception e){ System.out.println(e);}
}
}
Due Date of Submissi on 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.
--Solution --
Copy text
Due Date of Submissi on 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();
--Solution --
Copy text
}
catch (Exception e){ System.out.println(e);}
}
}
Due Date of Submissi on 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();
--Solution --
Copy text