Some questions and Answers on ASP NET MVC
Aug 06
এএসপি . নেট এম ভি সি এর উপর কিছু প্রশ্ন এবং উত্তর । Some questions and Answers on ASP.NET MVC
Aug 06
Some Questions and Answers on Razor View Engine
Some Questions and Answers on Razor View Engine
Aug 06
নোড.জেএস (Node. Js) টিউটোরিয়াল
মীর তাওহীদুল ইসলাম
ওয়েব ডেভেলপার
আজকে আপনাদের সামনে হাজির হলাম নোড জে এস এর টিউটোরিয়াল নিয়ে। আশা করি আপনাদের ভাল লাগবে।
নোড জে এস জাভাস্ক্রিপ্ট এর উপর ভিত্তি করে গড়ে ওঠা খুবই শক্তিশালী একটি ফ্রেমওয়ার্ক বা প্লাটফর্ম যা গুগল ক্রোমের জাভাস্ক্রিপ্ট ভি এইট ইঞ্জিনে (V8 Engine) এ তৈরি করা হয়েছে।
এই নোড জে এস ব্যাবহার হয় বিভিন্ন ধরনের ওয়েব অ্যাপলিকেশন তৈরিতে যেমনঃ অনলাইনে ভিডিও দেখার সাইট তৈরিতে, এক পেইজের অ্যাপলিকেশন তৈরিতে বা অন্যান্য ওয়েব অ্যাপলিকেশন তৈরিতে।
এই নোড জে এস একটি মুক্ত উৎস, সম্পূর্ণ ফ্রী এবং এটা সারা বিশ্বের হাজার হাজার ডেভেলপার এর ব্যাবহারের একটি উৎস।
এই টিউটোরিয়ালটি তৈরি করা হয়েছে সফটওয়্যার প্রোগ্রামারদের জন্য যারা নোড জে এস এর ব্যাসিক ও স্থাপত্য ধারনা গুলো সহজ সরল ভাবে শিখতে চায়।
এই টিউটোরিয়ালটি আপনাকে নোড জে এস এর উপাদান গুলো সম্পর্কে উপযুক্ত উদাহারনসহ খুব ভাল ধারনা দিবে।
এই টিউটোরিয়ালটি শুরুর পূর্বে অবশ্যই আপনার জাভাস্ক্রিপ্ট সম্পর্কে বেসিক ধারনা থাকতে হবে কারন আমরা এখন নোড জে এস ব্যাবহার করে একটি ওয়েব অ্যাপ্লিকেশন তৈরি করতে যাচ্ছি। এটা আপনার জন্য আরও ভালো হবে যদি আপনার আরও অন্যান্য ওয়েব প্রযুক্তি যেমন- এইচ টি এম এল (HTML), সি এস এস (CSS) , অ্যাজাক্স (AJAX) ইত্যাদি সম্পর্কেও বেসিক ধারনা থাকে।
আর এই টিউটোরিয়ালে যে উদাহারন গুলো থাকবে তা অবশ্যই নিজে নিজে চেষ্টা করতে হবে।
তাই প্রাথমিক ভাবে নিচে একটা উদাহারন কোড দেওয়া হলঃ
/*Hello World ! My First Programme In Node. Js*/
Console.log (“Hello World !”) ;
Aug 06
Install Kentico CMS in Localhost
Install Kentico CMS in Localhost
https://www.youtube.com/watch?v=KFcnunBi2GM
Aug 06
EmployeeCreation.java: Make a simple “employees” table using the database utilities
package cwp;
import java.sql.*;
/** Make a simple "employees" table using DatabaseUtilities.
*/
public class EmployeeCreation {
public static Connection createEmployees(String driver,
String url,
String username,
String password,
boolean close) {
String format =
"(id int, firstname varchar(32), lastname varchar(32), " +
"language varchar(16), salary float)";
String[] employees =
{"(1, 'Wye', 'Tukay', 'COBOL', 42500)",
"(2, 'Britt', 'Tell', 'C++', 62000)",
"(3, 'Max', 'Manager', 'none', 15500)",
"(4, 'Polly', 'Morphic', 'Smalltalk', 51500)",
"(5, 'Frank', 'Function', 'Common Lisp', 51500)",
"(6, 'Justin', 'Timecompiler', 'Java', 98000)",
"(7, 'Sir', 'Vlet', 'Java', 114750)",
"(8, 'Jay', 'Espy', 'Java', 128500)" };
return(DatabaseUtilities.createTable(driver, url,
username, password,
"employees",
format, employees,
close));
}
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];
createEmployees(driver, url, username, password, true);
}
private static void printUsage() {
System.out.println("Usage: EmployeeCreation host dbName " +
"username password oracle|sybase.");
}
}
Aug 06
extract relevant data from a DBResults
# 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 05
EmployeeTest2.java: A test case for the database utilities. Prints results formatted as an HTML table.
package cwp;
import java.sql.*;
/** Connect to Oracle or Sybase and print "employees" table
* as an HTML table.
*
*/
public class EmployeeTest2 {
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];
String query = "SELECT * FROM employees";
DBResults results =
DatabaseUtilities.getQueryResults(driver, url,
username, password,
query, true);
System.out.println(results.toHTMLTable("CYAN"));
}
private static void printUsage() {
System.out.println("Usage: EmployeeTest2 host dbName " +
"username password oracle|sybase.");
}
}
Aug 05
DBResults.java: Class to store completed results of a JDBC Query. Differs from a ResultSet in several ways
# DBResults.java Class to store completed results of a JDBC Query. Differs from a ResultSet in several ways: * ResultSet doesn?t necessarily have all the data; reconnection to database occurs as you ask for later rows. * This class stores results as strings, in arrays. * This class includes DatabaseMetaData (database product name and version) and ResultSetMetaData (the column names). * This class has a toHTMLTable method that turns the results into a long string corresponding to an HTML table.
package cwp;
import java.sql.*;
import java.util.*;
/** Class to store completed results of a JDBC Query.
* Differs from a ResultSet in several ways:
*
*
ResultSet doesn't necessarily have all the data;
* reconnection to database occurs as you ask for
* later rows.
*
This class stores results as strings, in arrays.
*
This class includes DatabaseMetaData (database product
* name and version) and ResultSetMetaData
* (the column names).
*
This class has a toHTMLTable method that turns
* the results into a long string corresponding to
* an HTML table.
*
*
*/
public class DBResults {
private Connection connection;
private String productName;
private String productVersion;
private int columnCount;
private String[] columnNames;
private Vector queryResults;
String[] rowData;
public DBResults(Connection connection,
String productName,
String productVersion,
int columnCount,
String[] columnNames) {
this.connection = connection;
this.productName = productName;
this.productVersion = productVersion;
this.columnCount = columnCount;
this.columnNames = columnNames;
rowData = new String[columnCount];
queryResults = new Vector();
}
public Connection getConnection() {
return(connection);
}
public String getProductName() {
return(productName);
}
public String getProductVersion() {
return(productVersion);
}
public int getColumnCount() {
return(columnCount);
}
public String[] getColumnNames() {
return(columnNames);
}
public int getRowCount() {
return(queryResults.size());
}
public String[] getRow(int index) {
return((String[])queryResults.elementAt(index));
}
public void addRow(String[] row) {
queryResults.addElement(row);
}
/** Output the results as an HTML table, with
* the column names as headings and the rest of
* the results filling regular data cells.
*/
public String toHTMLTable(String headingColor) {
StringBuffer buffer =
new StringBuffer("\n");
if (headingColor != null) {
buffer.append(" \n ");
} else {
buffer.append(" \n ");
}
for(int col=0; col" + columnNames[col]);
}
for(int row=0; row\n ");
String[] rowData = getRow(row);
for(int col=0; col" + rowData[col]);
}
}
buffer.append("\n");
return(buffer.toString());
}
}
Aug 04
DatabaseUtilities.java: Several general-purpose utilities discussed and used in the chapter.
package cwp;
import java.sql.*;
/** Three database utilities:
* 1) getQueryResults. Connects to a database, executes
* a query, retrieves all the rows as arrays
* of strings, and puts them inside a DBResults
* object. Also places the database product name,
* database version, and the names of all the columns
* into the DBResults object. This has two versions:
* one that makes a new connection and another that
* uses an existing connection.
* 2) createTable. Given a table name, a string denoting
* the column formats, and an array of strings denoting
* the row values, this method connects to a database,
* removes any existing versions of the designated
* table, issues a CREATE TABLE command with the
* designated format, then sends a series of INSERT INTO
* commands for each of the rows. Again, there are
* two versions: one that makes a new connection and
* another that uses an existing connection.
* 3) printTable. Given a table name, this connects to
* the specified database, retrieves all the rows,
* and prints them on the standard output.
*/
public class DatabaseUtilities {
/** Connect to database, execute specified query,
* and accumulate results into DBRresults object.
* If the database connection is left open (use the
* close argument to specify), you can retrieve the
* connection via DBResults.getConnection.
*/
public static DBResults getQueryResults(String driver,
String url,
String username,
String password,
String query,
boolean close) {
try {
Class.forName(driver);
Connection connection =
DriverManager.getConnection(url, username, password);
return(getQueryResults(connection, query, close));
} catch(ClassNotFoundException cnfe) {
System.err.println("Error loading driver: " + cnfe);
return(null);
} catch(SQLException sqle) {
System.err.println("Error connecting: " + sqle);
return(null);
}
}
/** Retrieves results as in previous method, but uses
* an existing connection instead of opening a new one.
*/
public static DBResults getQueryResults(Connection connection,
String query,
boolean close) {
try {
DatabaseMetaData dbMetaData = connection.getMetaData();
String productName =
dbMetaData.getDatabaseProductName();
String productVersion =
dbMetaData.getDatabaseProductVersion();
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery(query);
ResultSetMetaData resultsMetaData =
resultSet.getMetaData();
int columnCount = resultsMetaData.getColumnCount();
String[] columnNames = new String[columnCount];
// Column index starts at 1 (ala SQL) not 0 (ala Java).
for(int i=1; i
