BGColor.jsp Page that demonstrates JSP scriptlets. Uses the JSP-Styles style sheet.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!--
Taken from Core Web Programming Java 2 Edition
from Prentice Hall and Sun Microsystems Press,
.
May be freely used or adapted.
-->
<HTML>
<HEAD>
<TITLE>Color Testing</TITLE>
</HEAD>
<%
String bgColor = request.getParameter("bgColor");
boolean hasExplicitColor = true;
if (bgColor == null) {
hasExplicitColor = false;
bgColor = "WHITE";
}
%>
<BODY BGCOLOR="<%= bgColor %>">
<H2 ALIGN="CENTER">Color Testing</H2>
<%
if (hasExplicitColor) {
out.println("You supplied an explicit background color of " +
bgColor + ".");
} else {
out.println("Using default background color of WHITE. " +
"Supply the bgColor request attribute to try " +
"a standard color or RRGGBB value, or to see " +
"if your browser supports X11 color names.");
}
%>
</BODY>
</HTML>
Aug 10
BGColor.jsp Page that demonstrates JSP scriptlets. Uses the JSP-Styles style sheet.
Aug 10
Excel.jsp Page that demonstrates the use of JSP to build Excel spreadsheets
Excel.jsp Page that demonstrates the use of JSP to build Excel spreadsheets First Last Email Address Marty Hall hall@corewebprogramming.com Larry Brown brown@corewebprogramming.com Bill Gates gates@sun.com Larry Ellison ellison@microsoft.com <%@ page contentType="application/vnd.ms-excel" %> <%-- There are tabs, not spaces, between columns. --%>
Aug 09
Expressions.jsp Page that demonstrates JSP expressions. Uses the JSP-Styles style sheet.
Expressions.jsp Page that demonstrates JSP expressions. Uses the JSP-Styles style sheet.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!--
Example of JSP Expressions.
Taken from Core Web Programming Java 2 Edition
from Prentice Hall and Sun Microsystems Press,
.
May be freely used or adapted.
-->
<HTML>
<HEAD>
<TITLE>JSP Expressions</TITLE>
<META NAME="keywords"
CONTENT="JSP,expressions,JavaServer,Pages,servlets">
<META NAME="description"
CONTENT="A quick example of JSP expressions.">
<LINK REL=STYLESHEET
HREF="JSP-Styles.css"
TYPE="text/css">
</HEAD>
<BODY>
<H2>JSP Expressions</H2>
<UL>
<LI>Current time: <%= new java.util.Date() %>
<LI>Your hostname: <%= request.getRemoteHost() %>
<LI>Your session ID: <%= session.getId() %>
<LI>The <CODE>testParam</CODE> form parameter:
<%= request.getParameter("testParam") %>
</UL>
</BODY>
</HTML>
Aug 09
ImportAttribute.jsp Page that demonstrates the import attribute of the page directive. Uses the ServletUtilities class
ImportAttribute.jsp Page that demonstrates the import attribute of the page directive. Uses the ServletUtilities class (Check Servlet Section)
<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.0 Transitional//EN”>
<!–
Example of the import attribute of the page directive.
Taken from Core Web Programming Java 2 Edition
from Prentice Hall and Sun Microsystems Press,
.
May be freely used or adapted.
–>
<HTML>
<HEAD>
<TITLE>The import Attribute</TITLE>
<LINK REL=STYLESHEET
HREF=”JSP-Styles.css”
TYPE=”text/css”>
</HEAD>
<BODY>
<H2>The import Attribute</H2>
<%– JSP page directive –%>
<%@ page import=”java.util.*,cwp.*” %>
<%– JSP Declaration –%>
<%!
private String randomID() {
int num = (int)(Math.random()*10000000.0);
return(“id” + num);
}
private final String NO_VALUE = “<I>No Value</I>”;
%>
<%– JSP Scriptlet –%>
<%
Cookie[] cookies = request.getCookies();
String oldID =
ServletUtilities.getCookieValue(cookies, “userID”, NO_VALUE);
if (oldID.equals(NO_VALUE)) {
String newID = randomID();
Cookie cookie = new Cookie(“userID”, newID);
response.addCookie(cookie);
}
%>
<%– JSP Expressions –%>
This page was accessed on <%= new Date() %> with a userID
cookie of <%= oldID %>.
</BODY>
</HTML>
Aug 08
Some questions and answers on SQL and MS SQL Server
Some questions and answers on SQL and MS SQL Server
https://youtu.be/LsCPnY3MKnA
Aug 08
QueryViewer.java: An interactive database query viewer
# QueryViewer.java An interactive database query viewer. Connects to the specified Oracle or Sybase database, executes a query, and presents the results in a JTable. Uses the following file:
* DBResultsTableModel.java Simple class that tells a JTable how to extract relevant data from a DBResults object (which is used to store the results from a database query).
############################################################################
package cwp;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.*;
/** An interactive database query viewer. Connects to
* the specified Oracle or Sybase database, executes a query,
* and presents the results in a JTable.
*
*/
public class QueryViewer extends JFrame
implements ActionListener{
public static void main(String[] args) {
new QueryViewer();
}
private JTextField hostField, dbNameField,
queryField, usernameField;
private JRadioButton oracleButton, sybaseButton;
private JPasswordField passwordField;
private JButton showResultsButton;
Container contentPane;
private JPanel tablePanel;
public QueryViewer () {
super("Database Query Viewer");
WindowUtilities.setNativeLookAndFeel();
addWindowListener(new ExitListener());
contentPane = getContentPane();
contentPane.add(makeControlPanel(), BorderLayout.NORTH);
pack();
setVisible(true);
}
/** When the "Show Results" button is pressed or
* RETURN is hit while the query textfield has the
* keyboard focus, a database lookup is performed,
* the results are placed in a JTable, and the window
* is resized to accommodate the table.
*/
public void actionPerformed(ActionEvent event) {
String host = hostField.getText();
String dbName = dbNameField.getText();
String username = usernameField.getText();
String password =
String.valueOf(passwordField.getPassword());
String query = queryField.getText();
int vendor;
if (oracleButton.isSelected()) {
vendor = DriverUtilities.ORACLE;
} else {
vendor = DriverUtilities.SYBASE;
}
if (tablePanel != null) {
contentPane.remove(tablePanel);
}
tablePanel = makeTablePanel(host, dbName, vendor,
username, password,
query);
contentPane.add(tablePanel, BorderLayout.CENTER);
pack();
}
// Executes a query and places the result in a
// JTable that is, in turn, inside a JPanel.
private JPanel makeTablePanel(String host,
String dbName,
int vendor,
String username,
String password,
String query) {
String driver = DriverUtilities.getDriver(vendor);
String url = DriverUtilities.makeURL(host, dbName, vendor);
DBResults results =
DatabaseUtilities.getQueryResults(driver, url,
username, password,
query, true);
JPanel panel = new JPanel(new BorderLayout());
if (results == null) {
panel.add(makeErrorLabel());
return(panel);
}
DBResultsTableModel model =
new DBResultsTableModel(results);
JTable table = new JTable(model);
table.setFont(new Font("Serif", Font.PLAIN, 17));
table.setRowHeight(28);
JTableHeader header = table.getTableHeader();
header.setFont(new Font("SansSerif", Font.BOLD, 13));
panel.add(table, BorderLayout.CENTER);
panel.add(header, BorderLayout.NORTH);
panel.setBorder
(BorderFactory.createTitledBorder("Query Results"));
return(panel);
}
// The panel that contains the textfields, checkboxes,
// and button.
private JPanel makeControlPanel() {
JPanel panel = new JPanel(new GridLayout(0, 1));
panel.add(makeHostPanel());
panel.add(makeUsernamePanel());
panel.add(makeQueryPanel());
panel.add(makeButtonPanel());
panel.setBorder
(BorderFactory.createTitledBorder("Query Data"));
return(panel);
}
// The panel that has the host and db name textfield and
// the driver radio buttons. Placed in control panel.
private JPanel makeHostPanel() {
JPanel panel = new JPanel();
panel.add(new JLabel("Host:"));
hostField = new JTextField(15);
panel.add(hostField);
panel.add(new JLabel(" DB Name:"));
dbNameField = new JTextField(15);
panel.add(dbNameField);
panel.add(new JLabel(" Driver:"));
ButtonGroup vendorGroup = new ButtonGroup();
oracleButton = new JRadioButton("Oracle", true);
vendorGroup.add(oracleButton);
panel.add(oracleButton);
sybaseButton = new JRadioButton("Sybase");
vendorGroup.add(sybaseButton);
panel.add(sybaseButton);
return(panel);
}
// The panel that has the username and password textfields.
// Placed in control panel.
private JPanel makeUsernamePanel() {
JPanel panel = new JPanel();
usernameField = new JTextField(10);
passwordField = new JPasswordField(10);
panel.add(new JLabel("Username: "));
panel.add(usernameField);
panel.add(new JLabel(" Password:"));
panel.add(passwordField);
return(panel);
}
// The panel that has textfield for entering queries.
// Placed in control panel.
private JPanel makeQueryPanel() {
JPanel panel = new JPanel();
queryField = new JTextField(40);
queryField.addActionListener(this);
panel.add(new JLabel("Query:"));
panel.add(queryField);
return(panel);
}
// The panel that has the "Show Results" button.
// Placed in control panel.
private JPanel makeButtonPanel() {
JPanel panel = new JPanel();
showResultsButton = new JButton("Show Results");
showResultsButton.addActionListener(this);
panel.add(showResultsButton);
return(panel);
}
// Shows warning when bad query sent.
private JLabel makeErrorLabel() {
JLabel label = new JLabel("No Results", JLabel.CENTER);
label.setFont(new Font("Serif", Font.BOLD, 36));
return(label);
}
}
Aug 08
এইচএসসি – 2015 পরীক্ষার ফলাফল । HSC – 2015 Examination Result
এইচএসসি পরীক্ষার ফলাফল জানতে দেখুন
আগামী ০৯ই আগষ্ট থেকে এখান থেকে এইচ এস সি পরিক্ষার ফলাফল দেখতে পারবেন অথবা শিক্ষা বোর্ড এর ওয়েবসাইট http://www.educationboardresults.gov.bd/regular/index.php থেকেও রেজাল্ট দেখতে পারবেন।
মোবাইলের মাধ্যমে ফলাফল কিভাবে দেখবেন?
HSC (Space) আপনার বোর্ড এর নামের প্রথম তিন অক্ষর (Space) রোল নম্বর (Space) পাশের সন এবং (16200) এ পাঠিয়ে দিন।
উদাহরণ: আপনার মোবাইলের মেসেজ অপশনে যেয়ে HSC DHA 103774 2015 লিখুন এবং পাঠিয়ে দিন 16222 নম্বরে।
মাদরাসা বোর্ড এর জন্য Alim MAD 103774 2015 লিখুন এবং পাঠিয়ে দিন 16222 নম্বরে।
টেকনিক্যাল এডুকেশন বোর্ড এর জন্য HSC TEC 103774 2015 লিখুন এবং পাঠিয়ে দিন 16222 নম্বরে।
Aug 07
AccessCounts.jsp Page that demonstrates JSP declarations.
AccessCounts.jsp Page that demonstrates JSP declarations. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <!-- Taken from Core Web Programming Java 2 Edition from Prentice Hall and Sun Microsystems Press, . May be freely used or adapted. --> <HTML> <HEAD> <TITLE>JSP Declarations</TITLE> <META NAME="keywords" CONTENT="JSP,declarations,JavaServer,Pages,servlets"> <META NAME="description" CONTENT="A quick example of JSP declarations."> <LINK REL=STYLESHEET HREF="JSP-Styles.css" TYPE="text/css"> </HEAD> <BODY> <H1>JSP Declarations</H1> <%! private int accessCount = 0; %> <H2>Accesses to page since server reboot: <%= ++accessCount %></H2> </BODY> </HTML>
Aug 07
PreparedStatements.java An example to test the timing differences resulting from repeated raw queries vs. repeated calls
package cwp;
import java.sql.*;
/** An example to test the timing differences resulting
* from repeated raw queries vs. repeated calls to
* prepared statements. These results will vary dramatically
* among database servers and drivers. With my setup
* and drivers, Oracle prepared statements took only half
* the time that raw queries required when using a modem
* connection, and took only 70% of the time that
* raw queries required when using a fast LAN connection.
* Sybase times were identical in both cases.
*
*/
public class PreparedStatements {
public static void main(String[] args) {
if (args.length < 5) {
printUsage();
return;
}
String vendorName = args[4];
int vendor = DriverUtilities.getVendor(vendorName);
if (vendor == DriverUtilities.UNKNOWN) {
printUsage();
return;
}
String driver = DriverUtilities.getDriver(vendor);
String host = args[0];
String dbName = args[1];
String url =
DriverUtilities.makeURL(host, dbName, vendor);
String username = args[2];
String password = args[3];
// Use "print" only to confirm it works properly,
// not when getting timing results.
boolean print = false;
if ((args.length > 5) && (args[5].equals("print"))) {
print = true;
}
Connection connection =
getConnection(driver, url, username, password);
if (connection != null) {
doPreparedStatements(connection, print);
doRawQueries(connection, print);
}
}
private static void doPreparedStatements(Connection conn,
boolean print) {
try {
String queryFormat =
"SELECT lastname FROM employees WHERE salary > ?";
PreparedStatement statement =
conn.prepareStatement(queryFormat);
long startTime = System.currentTimeMillis();
for(int i=0; i<40; i++) {
statement.setFloat(1, i*5000);
ResultSet results = statement.executeQuery();
if (print) {
showResults(results);
}
}
long stopTime = System.currentTimeMillis();
double elapsedTime = (stopTime - startTime)/1000.0;
System.out.println("Executing prepared statement " +
"40 times took " +
elapsedTime + " seconds.");
} catch(SQLException sqle) {
System.out.println("Error executing statement: " + sqle);
}
}
public static void doRawQueries(Connection conn,
boolean print) {
try {
String queryFormat =
"SELECT lastname FROM employees WHERE salary > ";
Statement statement = conn.createStatement();
long startTime = System.currentTimeMillis();
for(int i=0; i<40; i++) {
ResultSet results =
statement.executeQuery(queryFormat + (i*5000));
if (print) {
showResults(results);
}
}
long stopTime = System.currentTimeMillis();
double elapsedTime = (stopTime - startTime)/1000.0;
System.out.println("Executing raw query " +
"40 times took " +
elapsedTime + " seconds.");
} catch(SQLException sqle) {
System.out.println("Error executing query: " + sqle);
}
}
private static void showResults(ResultSet results)
throws SQLException {
while(results.next()) {
System.out.print(results.getString(1) + " ");
}
System.out.println();
}
private static Connection getConnection(String driver,
String url,
String username,
String password) {
try {
Class.forName(driver);
Connection connection =
DriverManager.getConnection(url, username, password);
return(connection);
} catch(ClassNotFoundException cnfe) {
System.err.println("Error loading driver: " + cnfe);
return(null);
} catch(SQLException sqle) {
System.err.println("Error connecting: " + sqle);
return(null);
}
}
private static void printUsage() {
System.out.println("Usage: PreparedStatements host " +
"dbName username password " +
"oracle|sybase [print].");
}
}
