jdbc----(JAVA DATABASE CONNECTION )
cud operations
c-- cretae
create database <database>
create database sample
create table tablename(filename datatype(size(10))
create table student(name varchar(20), password varchar(30), email varchar(50) );
insert into studentvalues ('mahesh', 'baba','mahesh1206@gmail.com');
insert into studentvalues('abhi', 'reddy', 'abhi@gmail.com' );
install wamp server .
it its interface to provide mysql db
click on the shortcut
wamp server stars running click here for full procedure wamp installion
1. steps to create a table :
2.open wamp server go to php my admin create a database with one name
3.select the db
3.give the table name thn click on create
open wamp server seelct db click on sql
write the query ...
then click on go update :
syntax :--
update tablename set colname='data', where columnname='data';
example :update mahi set email='mahi@1206' where email='nani515@gmail.com' ;
To view table write the below code
syntax :--
select * from tablename;
syntax :--
select columnname from table name;
example:---
select name from mahi;
syntax :--
select max (columnname) from tablename;
example:---
3.Sselect name email ,marks from student where name='abcd';
To join two table there should a common column in two tables
example:---
select student .name, student.email,
fee.fee from student inner join fee on student .name=fee.name;
Delete :
syntax for Delete operation:--
delete from tablename where column name ;
TYPES OF JDBC DRIVERS
1.jdbc-odbc bridge driver .
2.native api driver
3.network protocol driver.
4.pure java driver .
jdbc is api it provide set of classses and interfaces
create a new projetc
1. load the driver
mysql:com.mysql.jdbc.Driver
oracle:oracle.jdbc.driver
ms-access:sun.jdbc.odbc.driver
class.forName("com.mysql.jdbc.driver") (//// yellow error in eclipse is package error or exception error )
class not found excption in psvm
2. establish the connection .
mysql:jdbc:mysql://localhost:3306/dbname
oracle:jdbc:oracle:thin:@localhost:1521:xe
ms-access:sun.jdbc.dbname
con is interface connection drivermanger is class , getconnetion is method get contion (url, user pass)
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/sample", "root","");
Here sample is database name you can change it into your database name
connection con=Drivermanger.getconnection("jdbc:oracle:thin:@localhost:1521:xe","system","admin");
XE is global db in oracle
// TODO Auto-generated method stub
String s1=request.getParameter("name");
String s2=request.getParameter("pwd");
String s3=request.getParameter("email");
try {
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/sample", "root","");
} catch (ClassNotFoundException | SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
3. write the queries :
i statemnet
ii.prepare statement
iii. callable statement
prepare statement is used to take data from user
if you want data in program we are using statment interface
if we want read data from clinet and pass to program we are using the preparestatemnt interface
to create procedure for table and to access callable statement
syntax :--
statement
st=con.createstatemnet(insert into student values ('ab', 'ab', 'abc@gmail.com');
syntax :--
PreparedStatement ps=con.preparestatemnet(insert into student values('abbda' ,'adads',' bbab@gmail.com)");
4 . excute the queries
i.. select query-->ps.executeQuery();
ii. non select query
ps.executeUpdate();
5.. close the connection
connection
con.close();
after the mysql connector.jar paste in you are project
rigth click on jar file click on build path
add to build path
You can download the source program from below link
JSP EXAMPLE PROJECT
LOGIN FORM USING JSP PAGE
DYNAMIC WEB PROJECT EXAMPLE
cud operations
c-- cretae
create database <database>
create database sample
create table tablename(filename datatype(size(10))
create table student(name varchar(20), password varchar(30), email varchar(50) );
insert into studentvalues ('mahesh', 'baba','mahesh1206@gmail.com');
insert into studentvalues('abhi', 'reddy', 'abhi@gmail.com' );
INSTALLTION OF WAMP SERVER
it its interface to provide mysql db
click on the shortcut
wamp server stars running click here for full procedure wamp installion
steps to create a database in project :
1. steps to create a table :
2.open wamp server go to php my admin create a database with one name
3.select the db
3.give the table name thn click on create
open wamp server seelct db click on sql
write the query ...
then click on go update :
syntax :--
update tablename set colname='data', where columnname='data';
example :update mahi set email='mahi@1206' where email='nani515@gmail.com' ;
To view table write the below code
syntax :--
select * from tablename;
syntax :--
select columnname from table name;
example:---
select name from mahi;
syntax :--
select max (columnname) from tablename;
example:---
1.select max(marks) from mahi;
2.select avg(marks) from mahi;3.Sselect name email ,marks from student where name='abcd';
To join two table there should a common column in two tables
example:---
select student .name, student.email,
fee.fee from student inner join fee on student .name=fee.name;
Delete :
syntax for Delete operation:--
TYPES OF JDBC DRIVERS
1.jdbc-odbc bridge driver .
2.native api driver
3.network protocol driver.
4.pure java driver .
jdbc is api it provide set of classses and interfaces
steps to connect with db using jdbc :----
open eclipsecreate a new projetc
1. load the driver
mysql:com.mysql.jdbc.Driver
oracle:oracle.jdbc.driver
ms-access:sun.jdbc.odbc.driver
class.forName("com.mysql.jdbc.driver") (//// yellow error in eclipse is package error or exception error )
class not found excption in psvm
2. establish the connection .
mysql:jdbc:mysql://localhost:3306/dbname
oracle:jdbc:oracle:thin:@localhost:1521:xe
ms-access:sun.jdbc.dbname
con is interface connection drivermanger is class , getconnetion is method get contion (url, user pass)
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/sample", "root","");
Here sample is database name you can change it into your database name
connection con=Drivermanger.getconnection("jdbc:oracle:thin:@localhost:1521:xe","system","admin");
XE is global db in oracle
// TODO Auto-generated method stub
String s1=request.getParameter("name");
String s2=request.getParameter("pwd");
String s3=request.getParameter("email");
try {
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/sample", "root","");
} catch (ClassNotFoundException | SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
3. write the queries :
i statemnet
ii.prepare statement
iii. callable statement
prepare statement is used to take data from user
if you want data in program we are using statment interface
if we want read data from clinet and pass to program we are using the preparestatemnt interface
to create procedure for table and to access callable statement
syntax :--
st=con.createstatemnet(insert into student values ('ab', 'ab', 'abc@gmail.com');
syntax :--
4 . excute the queries
i.. select query-->ps.executeQuery();
ii. non select query
ps.executeUpdate();
5.. close the connection
connection
con.close();
after the mysql connector.jar paste in you are project
rigth click on jar file click on build path
add to build path
You can download the source program from below link
sample projects for database :--
JDBC CONNECTION PROGRAMJSP EXAMPLE PROJECT
LOGIN FORM USING JSP PAGE
DYNAMIC WEB PROJECT EXAMPLE
No comments:
Post a Comment