0% found this document useful (0 votes)
5 views5 pages

Java JDBC JSP Multithreading Predicted Programs

The document contains four Java programming examples: a program to accept and display names in reverse using LinkedList, a JDBC program to accept and display student details from a PostgreSQL database, a JSP program for a simple login check where the username must match the password, and a multithreading example that prints numbers from 1 to 10 with a 2-second delay between each number. Each example includes code snippets and demonstrates different Java concepts. These programs are designed for a TYBSc CS curriculum focusing on Java, JDBC, JSP, and multithreading.

Uploaded by

Abhishek Kapse
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views5 pages

Java JDBC JSP Multithreading Predicted Programs

The document contains four Java programming examples: a program to accept and display names in reverse using LinkedList, a JDBC program to accept and display student details from a PostgreSQL database, a JSP program for a simple login check where the username must match the password, and a multithreading example that prints numbers from 1 to 10 with a 2-second delay between each number. Each example includes code snippets and demonstrates different Java concepts. These programs are designed for a TYBSc CS curriculum focusing on Java, JDBC, JSP, and multithreading.

Uploaded by

Abhishek Kapse
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

TYBSc CS - Java, JDBC, JSP & Multithreading Programs (Predicted)

1) Java Program: Accept 'n' names, store in LinkedList & display in reverse

import java.util.*;

public class ReverseNames {

public static void main(String args[]) {

Scanner sc = new Scanner(System.in);

LinkedList<String> list = new LinkedList<>();

System.out.print("Enter number of names: ");

int n = sc.nextInt();

sc.nextLine();

for(int i=0; i<n; i++) {

System.out.print("Enter name: ");

list.add(sc.nextLine());

Collections.reverse(list);

System.out.println("Names in reverse:");

for(String name : list)

System.out.println(name);

}
2) JDBC Program: Accept student details & display (roll, name, percent)

import java.sql.*;

import java.util.*;

public class StudentDB {

public static void main(String args[]) throws Exception {

Scanner sc = new Scanner(System.in);

System.out.print("Roll: "); int r = sc.nextInt();

sc.nextLine();

System.out.print("Name: "); String n = sc.nextLine();

System.out.print("Percent: "); float p = sc.nextFloat();

Connection con = DriverManager.getConnection("jdbc:postgresql://localhost/test", "postgres",

"Abhi2374");

PreparedStatement ps = con.prepareStatement("INSERT INTO student VALUES (?, ?, ?)");

ps.setInt(1, r); ps.setString(2, n); ps.setFloat(3, p);

ps.executeUpdate();

ResultSet rs = con.createStatement().executeQuery("SELECT * FROM student");

while(rs.next())

System.out.println(rs.getInt(1)+" "+rs.getString(2)+" "+rs.getFloat(3));

con.close();

}
3) JSP Program: Login check - username == password

login.jsp

<%@ page language="java" %>

<html>

<body>

<%

String u = request.getParameter("user");

String p = request.getParameter("pass");

if(u != null && u.equals(p))

out.print("<h2>Login Successful</h2>");

else

out.print("<h2>Login Failed</h2>");

%>

</body>

</html>

Form Page (form.html)

<form action="login.jsp">

Username: <input type="text" name="user"><br>

Password: <input type="text" name="pass"><br>

<input type="submit" value="Login">

</form>
4) Java Multithreading: Print 1 to 10 with 2 sec delay

class Count extends Thread {

public void run() {

for(int i=1; i<=10; i++) {

System.out.println(i);

try { Thread.sleep(2000); } catch(Exception e) {}

public static void main(String args[]) {

new Count().start();

You might also like