Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
19 views
Java Sec-D Database Connectivity
Java notes
Uploaded by
ritick.singh08
AI-enhanced title
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save JAVA SEC-D DATABASE CONNECTIVITY For Later
Download
Save
Save JAVA SEC-D DATABASE CONNECTIVITY For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
0 ratings
0% found this document useful (0 votes)
19 views
Java Sec-D Database Connectivity
Java notes
Uploaded by
ritick.singh08
AI-enhanced title
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save JAVA SEC-D DATABASE CONNECTIVITY For Later
Carousel Previous
Carousel Next
Save
Save JAVA SEC-D DATABASE CONNECTIVITY For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
Download now
Download
You are on page 1
/ 14
Search
Fullscreen
JAVA DATABASE CONNECTIVITY WITH Noer| 13.1 INTRODUCTION 132 JDBC 133 JAVASQL PACKAGE 134 WORKING WITH JDBC 13.4.1 CREATING A CONNECTION WITH THE DATABASE 13.4.2 INSERTING A RECORDING DATABASE 13.43 UPDATING AN EXISTING RECORD IN DATABASE 13.44 ACCESSING RECORDS FROM DATABASE. 13.4.5 DELETE A RECORD FROM DATABASE REVIEW QUESTIONS 131 Bz 133 15 335 136 188 339 1310 1313JAVA. DATABAS ASE CONNECTIVITY WITH | MY sql DODO Ee os00000000 131 INTRODUCTION 12 ypBc 183 JAVASQL PACKAGE 134 WORKING WITH JDBC 18.44 Creating a Connection withthe Datab 13.42 Inserting a Recordin Database 1945 Updating an Exiting Record in Database 134 Accessing Records from Database 1245 Delete a Record from Database REVIEW QUESTIONS ESE wrropuction ton ‘Adatabase isa collection of related information that is organized in such» way #8 ‘managed, and updated easily. Database touches all aspects of ou lives Some ofthe applications of database are as follows: Banking: all transactions * Airlines: reservations, schedules * Univenitis: registration, gradesJora Database Comeesvty Wh ain f lmtp taon soccer tote panemes nani | «paloma eocsug trmn ~ Npeeiiitadtiatsaean © lon el ead ed ls Den sas seme of en Qt mf ae Tiscali fw hues fe at Sted ns eh on has phe ae ers ac Saeco ald cua wef oman ld Te flown on =n ee rates : tone | Recom | tothe [aaa | a a ie fr | a a Eo] co a a a seam [ ea | — oon [actor rome rest nme ie tnt dope we et kang how to cen spas or idan dh Sn as a i0 Meat ure po Daa " Thee are folowing steps to be performed or connecting, Java application {) Impor a package named javasal in you avs appl ne (@) Lond andreister the JDBC driver Gi) Define the connection URL (x) Establish the connection withthe database (0) Createan objet of type Statement (+) ecute an SQL query using the methods of Statement objet (vi). Process the result (si) Close the connection | SUMMER 100 iad for Fava Database Connectivity. OAC oa sadn ve | Application Programming Interface (API) that allows the Programmers to access and manipulate _tashise management system through Java code, MER] vava.sou packace singmptpakage provides various iteraces and ass tht ae wad ty he JDBC AM os Meant #94 Processing data stored in a data source using the Java code, Some ofthe importa {and interface ofthis package areas follows Retister the Driver Class J method i we Ai ftName method of Cass clas is used to register the drive clas. Thi Samia oad te driver clas —— Tagg Ye to lad and register the diver to esublsh datakase cones NS code is used in Java program: as ¥ ARORADriverManager Class ae Connection Interface ae, ranection witha database, This can be done as follows jocalhost:3806 database" "username on=DriverManager getCannection(dbemysq: can communicate with the database. This can ement interface. Ths interface enables you to pert using the methods and properties of St nls to the database. You can perform insertion, deletion, updating, and searchi ResultSet Interface vides access to a table of data which is generated by executing a Statemen ct per Statement, It retrieves the rows from table in a sequc *, pointing to its current row of data, The ‘next()’ method is used to 1 ursor tothe next row of data. For example ezeating a statement ‘Statement stmt = con cteateSatement() Hesecoting a statement o retrieve the records from a table eoulSt = tt executsQuery eect alNo, studertName fom tabStuden's; Mint the es while. next) System out prints geting) + *), accessing by column index ‘tem out prints geShorstuden’Nam), accessing by colEET WORKING Wire spRc 124.1 CREATING A CONNECTION WitH THe pag ‘ © DATABASE, 2 Now use this database in MySql =: al for further man 5 command in MySql . Step: Now create a table named as tabStudents” in your database, containing the els No, studentName, and marks by executing the following command in Ni fe Ciprogram Fees ySQVASO Sener SDD mma 4 (Tete te same database and able for est ofthe pr Step: Now write the to establish MySql database 'studentDB ke Sepia sa farCemesdatinae Pb setic voiJuve Database Connectivity Wid i : Systm utp Problem wile extaishing the connection: Output of the Program 7 13.4.2 INSERTING A RECORD IN DATABASE sep |Crents ea ae ear ving Mya Sees and we ave cesta dtu named asstadem DB" by executing the flowin inna eo 2 Now use this database in MySql for furt Seri ——calhahaedoen Sal for further manipulations by executing th Leesa paste Connect » N a table named as “tabsi sve MdentName, and marks tudents" in your daa student a by executing be sin a lds oN, step: Now write the following code in your java application wo inant beens "ecord in "ahStudenty Inport vasa ls InsetRecord public state oid main(String ang) I Connection con = nl; Seatement tt = ll ( ‘Moad and Register the Driver Cas foeame( com mysql jdbe Drive’); Ss ‘establishing the connection with database ‘con=DriverManager getConnection("jdbc-mysqi//localhost3306/studestDB rot Wereating a statement stmt=con createStatement); Mexecuting a statement to insert a record into a table SimtexecuteUpdate( ‘insert into tabStudents values(/ Avinash’ 450) ‘WClosing the connection con close), _ — easjews 13.4.3 UPDATING AN EXISTING RECORD IN DATABASE agement System. Here, we are using MySql Server 50 Step-I: Create a database in a Database M ave ceated a database named asstudentDB Step-2: Now use this database in MySql fr further manipulations, steps “ e named as "abStudents" in your database, containing three fields rolNo, studentName, and marks. - ’ te cme goes rename ys Step-4: Insert some records in tabStudents table such as: Step-5: Now write the following code in your java application to update or tabStudents’ able : oo import oval ‘dass UpdateRecord 4s t Ste pes ee, i ‘Connection con null; = aac. 5 i Steeq) fstblishing the connection with daa creating 2 statement Closing the connection System out print "Recond Upuated Successful cateh(Exceptione) ‘Systemoutprintn(Thee isa problem: “4 Output of the Program i | BB C\Windows\system32\cmdexe Record Updated Successfully Press any key to continue « 13.4.4 ACCESSING RECORDS FROM DATABASE Re. system. Here, we are sing MySql SemerS2 Step-t: Create a database in a Database Management S and we have created a database named as “studentDB¥ S12 Now use this database in MySql fr further manipulations SHEPS: Now create a table named as “tabStudents’ in your database, containing studentName, and marks. (ote: Step-1 to Step-3 are samaS a te the following code in your java application t bli tate void mainString arg) ResultSet r= nl (MLoad and Register the Driver lass. for Name com mysql bc Dever" ‘establishing the connection with database ‘consDriverManager getConnection(jdbemysq:/ localhost 3906 /studentDBY00t"s) Hereating a statement tint=con creteStatement) ‘Texecuting a statement to acess records from tabStudes rssstmtexecuteQuery( select from laStudents) Display Records System out printing”———- Roll No \t Student Name \t Marks") a System out printin¢ Systemout printing hile(rs.nextO) i int mers getint"olINo’) String sName=rsgottring(studentName"); lint m= rs getin'marks") Systemoutprint(\" +m); System.outprint(\t”+ sName}:Sr oe 549 iol ro i re ren ri eer ra) foment’ Marks 134.8 DELETE A RECORD FROM DATABASE Step: Crate a database in a Database Management Syste and we have created a database named as “stude Step Now use this database in MySql for further manipulations Step Now create a table named as "tabStudents" in your database, conta studentName, and marks DB thre feds rollNo, (Note Step-1 to Step Sep Insert some records in tabStudent footer eer cies Cetin Peery cocoEstablishing the connection with database DriverManager,getConnection de mysql lecalhost’306/studentD8" ro ‘xecuting 4 satement o access records from tabStudents lat delete from tba where rllNe-2" {csecutng a statement to access remaining records from tbStudents ‘-stmt-executeQueryselet* frm tite) Srstem out print Records after deleting a record of Roll No: Display Records Roll No \t Student Name \t Mark”) = % System out printing wher. nent) int mars gettntrolNo*), String sName=rs getStringstudentName’) intm » rs getint’ marks", System out print(\t +m) Systemoutprint?\t" + sName) Systemoutprintn(” \t "+ my, ‘Closing the connectiona joo of the Program — output Po after deleting «rect Se Paat you can access and manipulate databases using [DBC ee ee = = = What is database? Wha are the applications of databases? Whats DBC? What is the use of java.sql package? Explain 1 2 5 ‘ 5. Whats the use of various classes and interfaces provided by java sql package? 6 Writ the steps to establish a connection with the database using JDBC 7, Wisite the steps to insert a recordin database using JDBC © White the steps to update an existing record in database using JDBC iq ng JDBC steps to delete apartcular record from database using JDBC Write the steps to access the records from datal 10. Write the gag sisase Connectivity WH
You might also like
6 JAVA MODULE5 Accessing Database
PDF
No ratings yet
6 JAVA MODULE5 Accessing Database
48 pages
DBMS EXP 9 Theory
PDF
No ratings yet
DBMS EXP 9 Theory
6 pages
Java Programming Chapter VII
PDF
No ratings yet
Java Programming Chapter VII
23 pages
The Mysql JDBC Driver
PDF
No ratings yet
The Mysql JDBC Driver
7 pages
Java Programming Chapter-7 JDBC-1
PDF
No ratings yet
Java Programming Chapter-7 JDBC-1
39 pages
Database Connectivity Pages Deleted
PDF
No ratings yet
Database Connectivity Pages Deleted
35 pages
Database Connectivity To Mysql: Tables SQL
PDF
No ratings yet
Database Connectivity To Mysql: Tables SQL
32 pages
JDBC Documentation
PDF
No ratings yet
JDBC Documentation
9 pages
Lecture Notes of Java Java Database Connectivity (JDBC)
PDF
No ratings yet
Lecture Notes of Java Java Database Connectivity (JDBC)
23 pages
Database Connectivity in Java and JDBC
PDF
No ratings yet
Database Connectivity in Java and JDBC
8 pages
Chapter 6-DatabaseConnectivity Final
PDF
No ratings yet
Chapter 6-DatabaseConnectivity Final
36 pages
Databases Concepts
PDF
No ratings yet
Databases Concepts
42 pages
9 Java and MySQL
PDF
No ratings yet
9 Java and MySQL
4 pages
JDBC
PDF
No ratings yet
JDBC
60 pages
JDBC
PDF
No ratings yet
JDBC
26 pages
Java JDBC (Unit-4)
PDF
No ratings yet
Java JDBC (Unit-4)
49 pages
Chapter 8. JDBC: ITSS Java Programming NGUYEN Hong Quang, HUT
PDF
No ratings yet
Chapter 8. JDBC: ITSS Java Programming NGUYEN Hong Quang, HUT
38 pages
Java JDBC (Unit-4)
PDF
No ratings yet
Java JDBC (Unit-4)
49 pages
5.3 JDBC Drivers - connectivity
PDF
No ratings yet
5.3 JDBC Drivers - connectivity
7 pages
Lab 12 - Java Database Connectivity (JDBC)
PDF
No ratings yet
Lab 12 - Java Database Connectivity (JDBC)
15 pages
JDBC
PDF
No ratings yet
JDBC
51 pages
Chapter 6
PDF
No ratings yet
Chapter 6
42 pages
Chapter 9 Database Connectivity
PDF
No ratings yet
Chapter 9 Database Connectivity
27 pages
Database Connectivity To Mysql: Informatics Practices Class Xii By-Deepak Bhinde PGT Comp. SC
PDF
No ratings yet
Database Connectivity To Mysql: Informatics Practices Class Xii By-Deepak Bhinde PGT Comp. SC
27 pages
Lecture 15 Database Concepts
PDF
No ratings yet
Lecture 15 Database Concepts
53 pages
Chapter 03-Java Database Connectivity
PDF
No ratings yet
Chapter 03-Java Database Connectivity
38 pages
Unit Iii
PDF
No ratings yet
Unit Iii
15 pages
JDBC
PDF
No ratings yet
JDBC
31 pages
Mysql Basics and Installation: by Debasis Samanta
PDF
No ratings yet
Mysql Basics and Installation: by Debasis Samanta
32 pages
Chapter Six Java Database Connectivity: Debre Markos University Department of Computer Science
PDF
No ratings yet
Chapter Six Java Database Connectivity: Debre Markos University Department of Computer Science
24 pages
Chapter 7-Java Database Connectivity
PDF
No ratings yet
Chapter 7-Java Database Connectivity
44 pages
Java Database Connectivity (2)
PDF
No ratings yet
Java Database Connectivity (2)
35 pages
How Does JDBC Work Details About JDBC How To Set Up An Access Database in Windows A JDBC Example SQL
PDF
No ratings yet
How Does JDBC Work Details About JDBC How To Set Up An Access Database in Windows A JDBC Example SQL
8 pages
JDBC by Attaullah
PDF
No ratings yet
JDBC by Attaullah
5 pages
Compile: C: CD /mywebproject Javac Jdbcselecttest - Java
PDF
No ratings yet
Compile: C: CD /mywebproject Javac Jdbcselecttest - Java
6 pages
2 Best-JDBC Final
PDF
No ratings yet
2 Best-JDBC Final
64 pages
JDBC
PDF
No ratings yet
JDBC
22 pages
Slide 2
PDF
No ratings yet
Slide 2
77 pages
Unit 5
PDF
No ratings yet
Unit 5
14 pages
JDBC - J D B C: Ava Ata Ase Onnectivity
PDF
No ratings yet
JDBC - J D B C: Ava Ata Ase Onnectivity
40 pages
Chapter 3 JDBC
PDF
No ratings yet
Chapter 3 JDBC
24 pages
TDA357 L09 Jdbc,Security
PDF
No ratings yet
TDA357 L09 Jdbc,Security
40 pages
Exam QuestionsAndSolutions
PDF
No ratings yet
Exam QuestionsAndSolutions
15 pages
JDBC
PDF
No ratings yet
JDBC
19 pages
Unit2 Part-2 JDBC Programming
PDF
No ratings yet
Unit2 Part-2 JDBC Programming
24 pages
Java MySQL JDBC Tutorial Using NetBeans
PDF
100% (1)
Java MySQL JDBC Tutorial Using NetBeans
10 pages
JDBC New
PDF
No ratings yet
JDBC New
14 pages
unit V
PDF
No ratings yet
unit V
60 pages
841161958
PDF
No ratings yet
841161958
31 pages
Java Database Connectivity
PDF
No ratings yet
Java Database Connectivity
39 pages
Mysql and Java: 1 Requirements
PDF
100% (1)
Mysql and Java: 1 Requirements
7 pages
Advanced-Java-Notes
PDF
No ratings yet
Advanced-Java-Notes
53 pages
JDBC Notes
PDF
No ratings yet
JDBC Notes
22 pages
JDBC p1
PDF
No ratings yet
JDBC p1
17 pages
Unit 8 2
PDF
No ratings yet
Unit 8 2
8 pages
Ipwt 3
PDF
No ratings yet
Ipwt 3
5 pages
Advance Java Labmanual
PDF
No ratings yet
Advance Java Labmanual
58 pages
Java JDBC
PDF
No ratings yet
Java JDBC
12 pages