ja12
- Write a JSP program to check whether given number is Perfect or not. (Use Include
directive). [15 M]
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
- Write a Java Program to create a PROJECT table with field’s project_id, Project_name,
Project_description, Project_Status. Insert values in the table. Display all the details of
the PROJECT table in a tabular format on the screen.(using swing).
import javax.swing.;
import java.awt.;
import java.sql.*;
public class ProjectTableDisplay extends JFrame {
private JTable table;
public ProjectTableDisplay() {
setTitle("Project Table");
setSize(600, 400);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setLocationRelativeTo(null);
try {
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM PROJECT");
ResultSetMetaData rsmd = rs.getMetaData();
int columnCount = rsmd.getColumnCount();
String[] columnNames = new String[columnCount];
for (int i = 1; i <= columnCount; i++) {
columnNames[i - 1] = rsmd.getColumnName(i);
}
Object[][] data = new Object[100][columnCount];
int row = 0;
while (rs.next()) {
for (int i = 1; i <= columnCount; i++) {
data[row][i - 1] = rs.getString(i);
}
row++;
}
table = new JTable(data, columnNames);
JScrollPane scrollPane = new JScrollPane(table);
add(scrollPane, BorderLayout.CENTER);
con.close();
} catch (Exception e) {
System.out.println(e);
}
setVisible(true);
}
public static void main(String[] args) {
new ProjectTableDisplay();
}
}