Posts

Showing posts from 2010

Adding dynamic content via expressions in jsp

any HTML file can be turned into a JSP file by changing its extension to .jsp.  Of course, what makes JSP useful is the ability to embed Java.  Put the following text in a file with .jsp extension (let us call it hello.jsp ), place it in your JSP directory, and view it in a browser.  <HTML> <BODY> Hello!  The time is now <%= new java.util.Date() %> </BODY> </HTML> Notice that each time you reload the page in the browser, it comes up with the current time. The character sequences <%= and %> enclose Java expressions, which are evaluated at run time. This is what makes it possible to use JSP to generate dyamic HTML pages that change in response to user actions or vary from user to user. Exercise :   Write a JSP to output the values returned by System.getProperty for various system properties such as java.version, java.home, os.name, user.name, user.home, user.dir etc.  

jdbc Statements to update and execute query

Image
JDBC Drivers The connection to the database is handled by the JDBC Driver class. The Java SDK contains only one JDBC driver, a jdbc-odbc bridge that can communicate with an existing Open DataBase Conectivity (ODBC) driver. Other databases need a JDBC driver specific to that database. To get a general idea of what the JDBC driver does, you can examine the JDCConnectionDriver.java file. The JDCConnectionDriver class implements the java.sql.Driver class and acts as a pass-through driver by forwarding JDBC requests to the real database JDBC Driver. The JDBC driver class is loaded with a call to Class.forName(drivername) . These next lines of code show how to load three different JDBC driver classes:   Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");   Class.forName("postgresql.Driver");   Class.forName("oracle.jdbc.driver.OracleDriver"); Each JDBC driver is configured to understand a specific URL so multiple JDBC drivers can be loaded at any one t

jdbc query execution

import java.sql.* ;   class JDBCQuery {  public static void main( String args[] )  {   try      {       // Load the database driver       Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver" ) ;         // Get a connection to the database       Connection conn = DriverManager.getConnection( "jdbc:odbc:Database" ) ;         // Print all warnings       for( SQLWarning warn = conn.getWarnings(); warn != null; warn = warn.getNextWarning() )          {           System.out.println( "SQL Warning:" ) ;           System.out.println( "State  : " + warn.getSQLState()  ) ;           System.out.println( "Message: " + warn.getMessage()   ) ;           System.out.println( "Error  : " + warn.getErrorCode() ) ;          }         // Get a statement from the connection       Statement stmt = conn.createStatement() ;         // Execute the query       ResultSet rs = stmt.executeQuery( "SELEC

inserting multiple values in table at a time

What is the optimal way to insert multiple rows (around 1000) from a web application into a table? The user enters multiple lines into a text box (up to 10,000). The ASP.NET application breaks that data into a string array. Each line is an item of that array. The user clicks Submit. I want to insert all those lines into a table in SQL Server. I know that with MySQL 4.00 and newer, I can simply issue the following command: INSERT INTO Table1 (field1) VALUES ('apple'), ('pear'), ('soda'), ('drink') This will very quickly insert all those values into Table1.field1. I know that in SQL Server, I can use a BULK INSERT from a file or BCP. However, I need to do the insert from a web application. It is better to create one large SqlCommand with all the insert statements: INSERT Table1 (field1) VALUES ('apple'); INSERT Table1 (field1) VALUES ('pear'); INSERT Table1 (field1) VALUES ('fruit'); INSERT Table1 (field

mysql jdbc connection code

package com.test; import java.sql.*;   public class MysqlConnect{   public static void main(String[] args) throws Exception {     System. out .println( "MySQL Connect Example." );     Connection conn = null ;     String url = "jdbc:mysql://localhost:3306/" ;     String dbName = "test" ;     String driver = "com.mysql.jdbc.Driver" ;     String userName = "fff" ;     String password = "bbb" ;     try {       Class. forName (driver).newInstance();       conn = DriverManager. getConnection (url+dbName,userName,password);       System. out .println( "Connected to the database" );       conn.close();       System. out .println( "Disconnected from database" );     } catch (Exception e) {       e.printStackTrace();     }   } }

Some Programes today

  Hy programmers This is my first page in My blog Good Luck for your programing.