Professional Documents
Culture Documents
The quest for knowledge can never end .The deeper you dig the greater the unexplored seems
to be. No man can honestly say that he has learned all, this world has to offer we cant achieve
anything worthwhile in any field only on the basis of theoretical knowledge from books,
According to my view programming knowledge is obtained through working at zero level and
gaining experience. Gathering new experiences and quest for learning something new
regarding technologies can never stop.
In order to get tangible and concrete results, the classroom knowledge needs to be effectively
wedded to the realities of the situation outside the classroom.
During my summer training program, as a part of it, I joined HEWLETT PACKARD
Enterprise of Chandigarh as a trainee after 6th semester. My assignment is based on CORE
JAVA .
This report covers the small introduction of HEWLETT PACKARD ENTERPRISE and
complete description of my language inhabited and implementation of it in my project.
i
ACKNOWLEDGEMENT
Apart from the efforts of me, the success of my project depends largely on the encouragement
and guidelines of many others. I take this opportunity to express my gratitude to the people
who have been instrumental in the completion of the project.
I would like to show my greatest appreciation to my project in-charge, Mr.Gagan. I cant say
thank you enough for their tremendous support and help. I feel motivated and encouraged every
time I attend his meeting. Without his encouragement and guideline this project work would
not have been materialized.
Akshay
1214012
ii
DECLARATION
I, Sahil hereby declare that the training report on CORE JAVA has not presented as a part of
any other academic work to get my degree or certificate except JMIT, Radaur for the fulfilment
of the requirement for the degree of Bachelor Electronics and Communication
Akshay
1214012
iii
INDEX
1) Certificate of Training
2) Introduction to Institution
3) Weekly schedule in organization
4) Introduction to Project
5) System Requirement Specification
6) Bibliography and References
7) Company contact details
iv
INTRODUCTION TO INSTITUTION
HEWLETT PACKARD ENTERPRISE has started with a vision to provide every solution
of IT. We have started with IT education & training and software solution In Web Design &
Development:
Vision / Mission:-
Our Vision
Our vision is to be the leader in Infrastructure Products, Services and creating value for
our customers to earn their Lifetime loyalty.
1
Our Mission
Every team member at HEWLETT PACKARD ENTERPRISE will strive to provide
Cost effective, Best Quality Products and Services to our customers through adherence
to and with continuous improvements in Standards, Systems and Processes.
Website Designing
Our services are backed by a professional work portfolio and glowing reviews. We have been
providing best-in-class web site design, web development, search engine optimization &
website maintenance services to Indian & offshore businesses since 2002. Our website design
services will get you the results that you always wanted. Our websites are clean, clear and
customized to your needs! Your website is an online resume for your business. Why wouldnt
you want to appear very best? At HEWLETT PACKARD, we provide professional website
designing and create custom logos at affordable prices.
We can improve the appearance of your web page templates, creating a visually appealing
layout that will encourage your visitors to linger and take the time to read the content on your
website instead of surfing the internet for other similar sites. Websites have emerged as a fast,
reliable and efficient media to display and share useful piece of information with the help &
use of pHewlett Packard ures, text and graphics. Within a short span of time we have designed
& developed a number of websites that are successfully fulfilling their objectives.
2
WEEKLY SCHEDULE IN AN INSTITUTION
Classes used to held regularly i.e six days a week .Every day a two and half hour class is used
to be there. For an hour, sir used to give us the theory classes and for rest one and half hour we
used to practice the concepts taught to us by the sir. It was a great learning experience to work
under the guidance of Mr. Sunil Khurrana who is our project guide.
3
Introduction to project
INTERFACE REQUIREMENT
1. User Interface
The package must be user friendly and robust. It must prompt the user with proper message
dialogue boxes to help them perform various actions and how to precede further the system
must respond normally under any in out conditions and display proper message instead of
turning up faults and errors.
In the following, we describe the software and hardware requirements for system developers
and system users. During our system development, we have to design both static and dynamic
website interfaces, create website functions and a database system, edit photos and pHewlett
Packard ures, and print out reports, so it has a set of software and hardware requirements.
Software Requirements
4
Hardware Requirements
CD-ROM : Required
5
2.1 Front-end Used
JAVA
With the invention of microprocessors, the world is scientifically developed with sophisticated
equipments, systems, and devices. Microprocessors are used in computers, televisions, and
fax machines. Even the hand-held devices such as pagers, PDAs (Personal Digital Assistant),
and cell phones make use of microprocessors. All these electronic devices are helpful because
of their communication capabilities. With the increasing capabilities and decreasing cost of
information processing and networking technologies, the network is growing rapidly for
transmitting information through electronic systems.
Internet is the network of networks between different types of computers located at different
places to transmit information. Information can reach to any place in the world quickly at a
cheaper rate through the Internet. Thus, the Internet has made the world a global village for
information exchange. The emerging infrastructure of electronic devices and interconnected
computer networks create an environment that presents new challenges to software industries.
for this emerging computing environment, Java process to be a well suited programming
language. it is found suitable for networked environments involving a great variety of
computer and devices.
6
The Java Programming Language
By the end of the 1980s and the early 1990s, object-oriented programming using C++ took
hold. Indeed, for a brief moment it seemed as if programmers had finally found the perfect
language. Because C++ blended the high efficiency and stylistic elements of C with the
object-oriented paradigm, it was a language that could be used to create a wide range of
programs. However, just as in the past, forces were brewing that would, once again, drive
computer language evolution forward. Within a few years, the World Wide Web and the
Internet would reach critical mass. This event would precipitate another revolution in
programming.
With most programming languages, you either compile or interpret a program so that
you can run it on your computer. The Java programming language is unusual in that a program
is both compiled and interpreted. With the compiler, first you translate a program into an
intermediate language called Java byte codes the platform-independent codes interpreted by
the interpreter on the Java platform. The interpreter parses and runs each Java byte code
instruction on the computer. Compilation happens just once; interpretation occurs each time
the program is executed. The following figure illustrates how this works
7
Platform independence - Many languages are compatible with only one platform. Java
was specifically designed so that it would run on any computer, regardless if it was
running Windows, Linux, Mac, Unix or any of the other operating systems.
Simple and easy to use - Java's creators tried to design it so code could be written
efficiently and easily.
Multi-functional - Java can produce many applications from command-line programs
to applets to Swing windows (basically, sophisticated graphical user interfaces).
Java does have some drawbacks. Since it has automated garbage collection, it can tend to use
more memory than other similar languages. There are often implementation differences on
different platforms, which have led to Java being described as a "write once, test everywhere"
system. Lastly, since it uses an abstract "virtual machine", a generic Java program doesn't have
access to the Native API's on a system directly. None of these issues are fatal, but it can mean
that Java isn't an appropriate choice for a particular piece of software.
8
The Java Platform
A platform is the hardware or software environment in which a program runs. We've already
mentioned some of the most popular platforms like Windows 2000, Linux, Solaris, and Mac
OS. Most platforms can be described as a combination of the operating system and hardware.
The Java platform differs from most other platforms in that it's a software-only platform that
runs on top of other hardware-based platforms
One thing that distinguished Java from some other languages is its ability to run the same
compiled code across multiple operating systems. In other languages, the source code (code
that is written by the programmer), is compiled by a compiler into an executable file. This file
is in machine language, and is intended for a single operating system/processor combination,
so the programmer would have to re-compile the program separately for each new operating
system/processor combination. Java is different in that it does not compile the code directly
into machine language code. Compilation creates byte code out of the source code. Byte code
generally looks something like this:
When the code is run by the user, it is processed by something called the
Java Virtual Machine (JVM). The JVM is essentially an interpreter for the byte code. It goes
through the byte code and runs it. There are different versions of the JVM that are compatible
with each OS and can run the same code. There is virtually no difference for the end-user, but
this makes it a lot easier for programmers doing software development.
In 2006 Sun started to make Java available under the GNU General Public License
(GPL). Oracle continues this project called OpenJDK.
9
Java programs are compiled by the Java compiler into bytecode. The Java virtual
machine interprets this bytecode and executes the Java program.
A Java distribution comes typically in two flavors, the Java Runtime Environment
(JRE) and the Java Development Kit (JDK).
The Java runtime environment (JRE) consists of the JVM and the Java class libraries
and contains the necessary functionality to start Java programs.
The JDK contains in addition the development tools necessary to create Java programs.
The JDK consists therefore of a Java compiler, the Java virtual machine, and the Java
class libraries.
The most common types of programs written in the Java programming language are
applets and applications. If you've accessed the Web, you're probably already familiar with
applets. An applet is a program that adheres to certain conventions that allow it to run within
a Java-enabled browser.
However, the Java programming language is not just for writing cute, entertaining
applets for the Web. The general-purpose, high-level Java programming language is also a
powerful software platform. Using the generous API, you can write many types of
programs.
An application is a standalone program that runs directly on the Java platform. A special
kind of application known as a server serves and supports clients on a network. Examples
of servers are Web servers, proxy servers, mail servers, and print servers. Another
specialized program is a servlet. A servlet can almost be thought of as an applet that runs
on the server side. Java Servlets are a popular choice for building interactive web
applications, replacing the use of CGI scripts. Servlets are similar to applets in that they are
runtime extensions of applications. Instead of working in browsers, though, servlets run
within Java Web servers, configuring or tailoring the server.
10
JFC and Swing
JFC and Swing is a part of java extension. JFC is short for Java Foundation Classes, which
encompass a group of features to help people build graphical user interfaces (GUIs). The
JFC was first announced at the 1997 Java One developer conference and is defined as
containing the following features:
Accessibility API
It enables assistive technologies such as screen readers and Braille displays to get
information from the user interface.
As a core part of the Java 2 Platform, Standard Edition (including versions 1.2,
1.3, and 1.4)
11
JFC 1.1 (for use with JDK 1.1)
Sun community recommends that to use the latest version of the Java 2 Platform. Not only
will you be getting the latest bug fixes, but you'll get more features. (As we used
JSDK1.5.0_01 version, which is the latest release of java development kit up to the time of
written of this report.)
In most cases, Java support is unnecessary in Web browsers, and security experts recommend
that it not be run in a browser unless absolutely necessary. It was suggested that, if Java is
required by a few Web sites, users should have a separate browser installation specifically for
those sites.
Generics
When generics were added to Java 5.0, there was already a large framework of classes (many
of which were already deprecated), so generics were chosen to be implemented using erasure
to allow for migration compatibility and re-use of these existing classes. This limited the
features that could be provided by this addition as compared to some other languages.
Java lacks native unsigned integer types. Unsigned data are often generated from programs
written in C and the lack of these types prevents direct data interchange between C and Java.
Unsigned large numbers are also used in many numeric processing fields, including
cryptography, which can make Java less convenient to use for these tasks. Although it is
possible to partially circumvent this problem with conversion code and using larger data
types, it makes using Java cumbersome for handling the unsigned data. While a 32-bit signed
integer may be used to hold a 16-bit unsigned value with relative ease, a 32-bit unsigned
value would require a 64-bit signed integer. Additionally, a 64-bit unsigned value cannot be
stored using any integer type in Java because no type larger than 64 bits exists in the Java
language. If abstracted using functions, function calls become necessary for many operations
which are native to some other languages. Alternatively, it is possible to use Java's signed
integers to emulate unsigned integers of the same size, but this requires detailed knowledge
of complex bitwise operations.
12
Floating point arithmetic
While Java's floating point arithmetic is largely based on IEEE 754(Standard for Binary
Floating-Point Arithmetic), certain features are not supported even when using the
strHewlett Packard fp modifier, such as Exception Flags and Directed Rounding capabilities
mandated by IEEE Standard 754. Additionally, the extended precision floating-point types
permitted in 754 and present in many processors are not permitted in Java.
Performance
In the early days of Java (before the Hot Spot VM was implemented in Java 1.3 in 2000)
there were some criticisms of performance. However, benchmarks typically report Java as
being about 50% slower than C (a language which compiles to native code).
Java's performance has improved substantially since the early versions. Performance of JIT
compilers relative to native compilers has in some optimized tests been shown to be quite
similar.
Java byte code can either be interpreted at run time by a virtual machine, or it can be
compiled at load time or runtime into native code which runs directly on the computer's
hardware. Interpretation is slower than native execution, and compilation at load time or
runtime has an initial performance penalty for the compilation. Modern per formant JVM
implementations all use the compilation approach, so after the initial startup time the
performance is equivalent to native code.
Security
The Java platform provides a security architecture which is designed to allow the user to run
untrusted bytecode in a "sandboxed" manner to protect against malicious or poorly written
software. This "sandboxing" feature is intended to protect the user by restrHewlett Packard
ing access to certain platform features and APIs which could be exploited by malware, such
as accessing the local file system, running arbitrary commands, or accessing communication
networks.
In recent years, researchers have discovered numerous security flaws in some widely used
Java implementations, including Oracle's, which allow untrusted code to bypass the
13
sandboxing mechanism, exposing users to malicious attacks. These flaws affect only Java
applications which execute arbitrary untrusted bytecode, such as web browser plug-ins that
run Java applets downloaded from public websites. Applications where the user trusts, and
has full control over, all code that is being executed are unaffected.
On August 31, 2012, Java 6 and 7 on Microsoft Windows, Mac OS X, and Linux were found
to have a serious security flaw that allowed a remote exploit to take place by simply loading a
malicious web page. Java 5 was later found to be flawed as well.
On January 10, 2013, three computer specialists spoke out against Java, telling Reuters that it
was not secure and that people should disable Java. Jaime Blasco, Labs Manager with
AlienVault Labs, stated that "Java is a mess. Its not secure. You have to disable it." This
vulnerability affects Java 7 and it is unclear if it affects Java 6, so it is suggested that
consumers disable it. Security alerts from Oracle announce schedules of critical security-
related patches to Java.
On January 14, 2013, security experts said that the update still failed to protect PCs from
attack. This exploit hole prompted a response from the United States Department of
Homeland Security encouraging users to disable or uninstall Java. Apple blacklisted Java in
limited order for all computers running its Mac OS X operating system through a virus
protection program.
Responding to recent Java security and vulnerability issues, security blogger Brian Krebs has
called for users to remove at least the Java browser plugin and also the entire software. "I
look forward to a world without the Java plugin (and to not having to remind readers about
quarterly patch updates) but it will probably be years before various versions of this plugin
are mostly removed from end-user systems worldwide."" "Once promising, it has outlived its
usefulness in the browser, and has become a nightmare that delights cyber-criminals at the
expense of computer users." "I think everyone should uninstall Java from all their PCs and
Macs, and then think carefully about whether they need to add it back. If you are a typical
home user, you can probably do without it. If you are a business user, you may not have a
choice."
Adware
The Java runtime environment has a history of bundling sponsored software to be installed by
default during installation and during the updates which roll out every month or so. This
includes the "Ask.com toolbar" that will redirect browser searches to ads and "McAfee
14
Security Scan Plus". These offers can be blocked through a setting in the Java Control Panel,
although this is not obvious.
Update system
Java is yet to release an automatic updater that does not require user intervention and
administrative rights unlike Google Chrome and Flash player.
15
2.2 Back End Used
The MySQL (R) software delivers a very fast, multi-threaded, multi-user, and robust SQL
(Structured Query Language) database server. MySQL Server is intended for mission-critical,
heavy-load production systems as well as for embedding into mass-deployed software. MySQL
is a trademark of MySQL AB.
The MySQL software is Dual Licensed. Users can choose to use the MySQL software as an
Open Source/Free Software product under the terms of the GNU General Public License or can
purchase a standard commercial license from MySQL AB. The MySQL web site
(http://www.mysql.com/) provides the latest information about the MySQL software.
We started out with the intention of using mSQL to connect to our tables using our own fast low-
level routines. However, after some testing, we came to the conclusion that mSQL was not fast
enough or flexible enough for our needs. This resulted in a new SQL interface to our database
but with almost the same API interface as mSQL. This API was designed to allow third-party
code that was written for use with mSQL to be ported easily for use with MySQL.
The derivation of the name MySQL is not clear. Our base directory and a large number of our
libraries and tools have had the prefix ``my'' for well over 10 years. However, co-founder Monty
Widenius's daughter is also named My, Which of the two gave its name to MySQL is still a
mystery, even for us.
The name of the MySQL Dolphin (our logo) is Sakila. Sakila was chosen by the founders of
MySQL AB from a huge list of names suggested by users in our ``Name the Dolphin'' contest.
The winning name was submitted by Ambrose Twebaze, an open software developer from
Swaziland, Africa. According to Ambrose, the name Sakila has its roots in SiSwati, the local
language of Swaziland. Sakila is also the name of a town in Arusha, Tanzania.
16
2.2.3 The Main Features of MySQL
The following list describes some of the important characteristics of the MySQL Database
Software
2. Column Types
17
3. Commands and Functions
Full operator and function support in the SELECT and WHERE clauses of queries. For
example:
Full support for SQL GROUP BY and ORDER BY clauses. Support for group functions
(COUNT(), COUNT(DISTINCT ...), AVG(), STD(), SUM(), MAX(), MIN(), and
GROUP_CONCAT()).
Support for LEFT OUTER JOIN and RIGHT OUTER JOIN with both standard SQL and
ODBC syntax.
Support for aliases on tables and columns as required by SQL-92.
DELETE, INSERT, REPLACE, and UPDATE return the number of rows that were
changed (affected). It is possible to return the number of rows matched instead by setting
a flag when connecting to the server.
The MySQL-specific SHOW command can be used to retrieve information about
databases, tables, and indexes. The EXPLAIN command can be used to determine how
the optimizer resolves a query.
Function names do not clash with table or column names. For example, ABS is a valid
column name. The only restrHewlett Packard ion is that for a function call, no spaces are
allowed between the function name and the `(' that follows it.
4. Security
A privilege and password system that is very flexible and secure, and allows host-based
verification. Passwords are secure because all password traffic is encrypted when you
connect to a server.
18
5. Scalability and Limits
Handles large databases. We use MySQL Server with databases that contain 50 million
records. We also know of users that use MySQL Server with 60,000 tables and about
5,000,000,000 rows.
Up to 32 indexes per table are allowed. Each index may consist of 1 to 16 columns or
parts of columns. The maximum index width is 500 bytes (this may be changed when
compiling MySQL Server). An index may use a prefix of a CHAR or VARCHAR
column.
6. Connectivity
Clients may connect to the MySQL server using TCP/IP sockets on any platform. On
Windows systems in the NT family (NT, 2000, or XP), clients may connect using named
pipes. On Unix systems, clients may connect using Unix domain socket files.
The Connector/ODBC interface provides MySQL support for client programs that use
ODBC (Open-DataBase-Connectivity) connections. For example, you can use MS
Access to connect to your MySQL server. Clients may be run on Windows or Unix.
Connector/ODBC source is available. All ODBC 2.5 functions are supported, as are
many others.
The Connector/JDBC interface provides MySQL support for Java client programs that
use JDBC connections. Clients may be run on Windows or Unix. Connector/JDBC
source is available.
The server can provide error messages to clients in many languages.
Full support for several different character sets, including ISO-8859-1 (Latin1), german,
big5, ujis, and more. For example, the Scandinavian characters `@^a', `@"a' and `@"o'
are allowed in table and column names. Unicode support is available as of MySQL
All data is saved in the chosen character set. All comparisons for normal string columns
are case-insensitive.
Sorting is done according to the chosen character set. It is possible to change this when
the MySQL server is started. To see an example of very advanced sorting, look at the
Czech sorting code. MySQL Server supports many different character sets that can be
specified at compile and runtime.
19
7. Clients and Tool
The MySQL server has built-in support for SQL statements to check, optimize, and
repair tables. These statements are available from the command line through the
mysqlcheck client. MySQL also includes myisamchk, a very fast command-line
utility for performing these operations on MyISAM tables.
All MySQL programs can be invoked with the --help or -? options to obtain online
assistance.
History
20
SYSTEM REQUIREMENT SPECIFICATION
a) NetBeans:
NetBeans refers to both a platform framework for Java desktop applications, and
an integrated development environment (IDE) for developing
with Java, JavaScript, PHP, Python, C, C++ and others. The NetBeans IDE is written in
Java and can run anywhere a compatible JVM is installed, including Windows, Mac OS,
Linux, and Solaris. A JDK is required for Java development functionality, but is not
required for development in other programming languages.
The NetBeans platform allows applications to be developed from a set of modular software
components called modules.
Applications can install modules dynamically. Any application can include the Update Center
module to allow users of the application to download digitally-signed upgrades and new
features directly into the running application. Reinstalling an upgrade or a new release does
not force users to download the entire application again.
The platform offers reusable services common to desktop applications, allowing developers
to focus on the logic specific to their application. Among the features of the platform are:
21
Storage management (saving and loading any kind of data)
Window management
Wizard framework (supports step-by-step dialogs)
NetBeans Visual Library
Integrated Development Tools
Introduction
Microsoft Access is a database management system (DBMS) from Microsoft that combines
the relational Microsoft Jet Database Engine with a graphical user interface and software-
Microsoft Access stores data in its own format based on the Access Jet Database Engine. It
can also import or link directly to data stored in other applications and databases.
Software developers, data architects and power users can use Microsoft Access to
develop application software. Like other Microsoft Office applications, Access is supported
by Visual Basic for Applications (VBA), an object-based programming language that can
reference a variety of objects including DAO (Data Access Objects), ActiveX Data Objects,
and many other ActiveX components. Visual objects used in forms and reports expose their
methods and properties in the VBA programming environment, and VBA code modules may
History
22
Project Omega
Microsoft's first attempt to sell a relational database product was during the mid 1980s, when
Microsoft obtained the license to sell RDBMS. In the late 1980s Microsoft developed its own
solution codenamed Omega. It was confirmed in 1988 that a database product for Windows
and OS/2 was in development. It was going to include the "EB" Embedded Basic
language, which was going to be the language for writing macros in all Microsoft
applications, but the unification of macro languages did not happen until the introduction
of Visual Basic for Applications (VBA).
Project Cirrus
After the Omega project was scrapped, some of its developers were assigned to the Cirrus
project (most were assigned to the team which created Visual Basic).Its goal was to create a
competitor for applications like Paradox or dBase that would work on Windows. After
Microsoft acquired FoxPro, there were rumors that the Microsoft project might get replaced
with it ,but the company decided to develop them in parallel. It was assumed that the project would
make of Extensible Storage Engine (Jet Blue) but, in the end, only support for Microsoft Jet
Database Engine (Jet Red) was provided.
Users can create tables, queries, forms and reports, and connect them together with macros.
Advanced users can use VBA write rich solutions with advanced data manipulation and user
control. Access also has report creation features that can work with any data source that
Access can access. The original concept of Access was for end users to be able to access data
from any source. Other features include: the import and export of data to many formats
Including Excel, Outlook, ASCII, dBase, Paradox, FoxPro, SQL Server and Oracle. It also
has ability to link to data in its existing location and use it for viewing, querying, editing, and
reporting. This allows the existing data to change while ensuring that Access uses the latest
data. It can perform heterogeneous joins between data sets stored across different platforms.
Access is often used by people downloading data from enterprise level databases for
manipulation, analysis, and reporting locally. There is also the Jet Database format (MDB or
ACCDB in Access 2007) which can contain the application and data in one file. This makes
it very convenient to distribute the entire application to another user, who can run it in
23
disconnected environments. One of the benefits of Access from a programmer's perspective is its
relative compatibility with SQL (structured query language) queries can be viewed graphically or
edited as SQL statements, and SQL statements can be used directly in Macros and
VBA Modules to manipulate Access tables. Users can mix and use both VBA and "Macros"
for programming forms and logic and offers object-oriented possibilities.
1. Setting up a Database: Firstly open a connection with your DBMS, and then,
since what JDBC does is to send your SQL code to your DBMS, we will
demonstrate some SQL code. After that, we will show you how easy it is to use
JDBC to pass these SQL statements to your DBMS and process the results that
are returned, also check some compatibility problems using it with older ODBC
drivers with the JDBC-ODBC Bridge.
2. Establishing a Connection: The first thing you need to do is establish a
connection with the DBMS you want to use.
24
This involves two steps: (a). loading the driver and (b).Making the connection.
(a). Loading Drivers : Loading the driver or drivers you want to use is very simple and
involves just one line of code. If, for example, you want to use the JDBC-ODBC Bridge driver,
the following code will load it:
Class.forName("com.mysql.jdbc.Driver");
conn=DriverManager.getConnection("jdbc:mysql://localHost:3306/login1","root","");
Your driver documentation will give you the class name to use. For instance, if the class
name is jdbc.DriverXYZ , you would load the driver with the following line of code:
You do not need to create an instance of a driver and register it with the
DriverManager because calling Class.forName will do that for you automatically. If you
were to create your own instance, you would be creating an unnecessary duplicate, but it
would do no harm.
When you have loaded a driver, it is available for making a connection with a DBMS.
(b). Making the connection : The second step in establishing a connection is to have the
appropriate driver connect to the DBMS. The following line of code illustrates the general idea:
This step is also simple, with the hardest thing being what to supply for url . If you are
using the JDBC-ODBC Bridge driver, the JDBC URL will start with jdbc:odbc: . The
rest of the URL is generally your data source name or database system. So, if you are
using ODBC to access an ODBC data source called " Fred, " for example, your JDBC
URL could be jdbc:odbc:Fred . In place of " myLogin " you put the name you use to
log in to the DBMS; in place of " myPassword " you put your password for the DBMS.
So if you log in to your DBMS with a login name of " Fernanda " and a password of "
J8, " just these two lines of code will establish a connection:
If you are using a JDBC driver developed by a third party, the documentation will tell
you what subprotocol to use, that is, what to put after jdbc: in the JDBC URL. For
25
example, if the driver developer has registered the name acme as the subprotocol, the
first and second parts of the JDBC URL will be jdbc:acme: . The driver documentation
will also give you guidelines for the rest of the JDBC URL. This last part of the JDBC
URL supplies information for identifying the data source.
If one of the drivers you loaded recognizes the JDBC URL supplied to the method
DriverManager.getConnection , that driver will establish a connection to the DBMS
specified in the JDBC URL. The DriverManager class, true to its name, manages all of
the details of establishing the connection for you behind the scenes. Unless you are
writing a driver, you will probably never use any of the methods in the interface Driver
and the only DriverManager method you really need to know is
DriverManager.getConnection .
At this point stmt exists, but it does not have an SQL statement to pass on to the DBMS.
We need to supply that to the method we use to execute stmt . For example, in the
following code fragment, we supply executeUpdate with the SQL statement from the
example above:
26
"(UNAME VARCHAR(32), PASSWORD INTEGER, PRICE FLOAT, " +
"SALES INTEGER, TOTAL INTEGER)");
Since we made a string out of the SQL statement and assigned it to the variable
createTableCoffees , we could have written the code in this alternate form:
stmt.executeUpdate(createTableCoffees);
The method used most often for executing SQL statements is executeQuery . This
method is used to execute SELECT statements, which comprise the vast majority of
SQL statements. You will see how to use this method shortly
5. Entering Data into a Table: We have shown how to create the table
COFFEES by specifying the names of the columns and the data types to be stored in
those columns, but this only sets up the structure of the table. The table does not yet
contain any data. We will enter our data into the table one row at a time, supplying the
information to be stored in each column of that row. Note that the values to be
inserted into the columns are listed in the same order that the columns were declared
when the table was created, which is the default order.
The following code inserts one row of data, with Colombian in the column
COF_NAME , 101 in SUP_ID , 7.99 in PRICE , 0 in SALES , and 0 in TOTAL . (Since
The Coffee Break has just started out, the amount sold during the week and the total to
date are zero for all the coffees to start with.) Just as we did in the code that created the
27
table COFFEES , we will create a Statement object and then execute it using the method
executeUpdate .
Since the SQL statement will not quite fit on one line on the page, we have split it into
two strings concatenated by a plus sign (+) so that it will compile. Pay special attention
to the need for a space between COFFEES and VALUES. This space must be within
the quotation marks and may be after COFFEES or before VALUES ; without a space,
the SQL statement will erroneously be read as " INSERT INTO COFFEESVALUES .
. ." and the DBMS will look for the table COFFEESVALUES . Also note that we use
single quotation marks around the coffee name because it is nested within double
quotation marks. For most DBMSs, the general rule is to alternate double quotation
marks and single quotation marks to indicate nesting.
The code that follows inserts a second row into the table COFFEES . Note that we can
just reuse the Statement object stmt rather than having to create a new one for each
execution.
28
29
BIBLIOGRAPHY AND REFERENCES
Contact no 9814005733
Website http://www.hpe.com
30