SlideShare ist ein Scribd-Unternehmen logo
1 von 18
ALEX JOSE
KV PATTOM SHIFT-I
CONCEPT MAPPING
 DriverManager Class : It is the class used to load
JDBC Driver needed to access particular database.
 Connection class : It manages the connection and
communication to the database.
 Statement Class: It contains the string that are
submitted to the database for execution. And it will
execute the SQL statement.
 ResultSet Class : If the statement class contains select
statement, then during the execution it will return
selected rows from the database are assigned to
ResultSet and it contains the methods to move
through the rows and get the values.
 Step1. import packages required for Database
Programming.
 Step2. Register the JDBC Driver.
 Open a connection.
 Execute a Query.
 Extract data from the ResultSet.
 Cleanup the environment.
DESIGN THE INTERFACE AS PER REQUIREMENT
 1. Import the packages required for Database
Programming
 import java.sql.*;
 2. Register the JDBC Driver with Java Program.
 Class.forName(“java.sql.DriverManager");
 3. Open the connection.
 This requires using the
DriverManager.getConnection() method to create
a connection object, which represents the
physical connection with the database. To
connect to the database, we need complete URL
to the database with userid and password of
MySQL.
 4. Execute a query.
 We need to create an object of type Statement or
PreparedStatement for building and submitting
an SQL statement to the database using the
createStatement() function of Connection class.
 in the Statement class executeQuery() method is
needed to execute select statement in SQL and
executeUpdate() method is to execute DML
statements.
 if the SQL command is Select statement we need
a class called ResultSet to store and process the
records.
 The Result set refers to a logical set of records
that are fetched from the database by executing
a query and made available to the application
program.
 next()
 moves the cursor forward one
 first()
 to move to the firts row.
 last()
 move the cursor to the lat lasr row.
 relative(int rows)
 moves the cursor relative to the current position.
 absolute(int rno)
 position the cursor on the rno th rows in the
ResultSet.
 getRow()
 to get the current cursor position.
Extract data from ResultSet
 ResultSet class has several methods to get
the values from the columns from the rows
pointed by the cursor.
 getInt("FieldName");
 getString("FieldName");
getString(fieldNumber);
 getFloat("FieldName");
 getDate("FieldName");
 getLong("FieldName");.
DISPLAYING DATA IN TABLES
 DefaultTableModel dtm=(javax.swing.table.DefaultTableModel)studenttab.getModel();
 int rows=dtm.getRowCount();
 if(rows>0)
 {
 for(int i=0;i<rows;i++)
 {
 dtm.removeRow(0);
 }
 }
 try
 {
 Class.forName("java.sql.DriverManager");
 Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/mydbll“,"root","");
 Statement stmt=con.createStatement();
 String str="select * from student";
 ResultSet rs=stmt.executeQuery(str);
 while(rs.next())
 {
 int sid=rs.getInt("stdid");
 String sname= rs.getString("stdname");
int mark= rs.getInt(“mark");
 Object obj[]={sid,sname,mark};
 dtm.addRow(obj);

 }
 }
 catch(Exception e)
 {
 System.out.println(e);
 }
 Executing the select statement having criteria.
 String str=”select * from student where stdid=”+
t1.getText;
 String str=”select * from student where stsname=’ ” +
tname.getText() +” ’ ”;

 To Execute DML commands
 Int sid=Integer.parseInt(t1.getText());
 String sname= tname.getText();
 Int mark=Integer.parseInt(tmark.getText());
 String str=”insert into student values(“+ sid+” , ’ “ +
sname +” ’ , “+ mark +”)”;
 Stmt.executeUpdate(str);
 String str=”delete * from student where stdid=” +
t1.getText() +”)”;
 Stmt.executeUpdate(str);

 String str=”update student set mark =mark+5 where
stdname=’ ” + tname.getText() +” ’ )”;
 Stmt.executeUpdate(str);
Java Databse Connectvity- Alex Jose

Weitere ähnliche Inhalte

Was ist angesagt?

Data structure and its types
Data structure and its typesData structure and its types
Data structure and its types
Navtar Sidhu Brar
 
Java collections
Java collectionsJava collections
Java collections
Amar Kutwal
 

Was ist angesagt? (20)

Intake 38 10
Intake 38 10Intake 38 10
Intake 38 10
 
Weka
WekaWeka
Weka
 
1 list datastructures
1 list datastructures1 list datastructures
1 list datastructures
 
MATLAB Bioinformatics tool box
MATLAB Bioinformatics tool boxMATLAB Bioinformatics tool box
MATLAB Bioinformatics tool box
 
Bca ii dfs u-1 introduction to data structure
Bca ii dfs u-1 introduction to data structureBca ii dfs u-1 introduction to data structure
Bca ii dfs u-1 introduction to data structure
 
3 searching algorithms in Java
3 searching algorithms in Java3 searching algorithms in Java
3 searching algorithms in Java
 
Java Collections | Collections Framework in Java | Java Tutorial For Beginner...
Java Collections | Collections Framework in Java | Java Tutorial For Beginner...Java Collections | Collections Framework in Java | Java Tutorial For Beginner...
Java Collections | Collections Framework in Java | Java Tutorial For Beginner...
 
Collections framework in java
Collections framework in javaCollections framework in java
Collections framework in java
 
Data structure and its types
Data structure and its typesData structure and its types
Data structure and its types
 
Java collections
Java collectionsJava collections
Java collections
 
2 b queues
2 b queues2 b queues
2 b queues
 
Matlab bioinformatics presentation
Matlab bioinformatics presentationMatlab bioinformatics presentation
Matlab bioinformatics presentation
 
Data structures
Data structuresData structures
Data structures
 
Java - Collections
Java - CollectionsJava - Collections
Java - Collections
 
2 a stacks
2 a stacks2 a stacks
2 a stacks
 
Data structures project
Data structures projectData structures project
Data structures project
 
Java Stack Data Structure.pptx
Java Stack Data Structure.pptxJava Stack Data Structure.pptx
Java Stack Data Structure.pptx
 
Advanced core java
Advanced core javaAdvanced core java
Advanced core java
 
ICOM4015_CIIC4010 Exam Review #2
ICOM4015_CIIC4010 Exam Review #2ICOM4015_CIIC4010 Exam Review #2
ICOM4015_CIIC4010 Exam Review #2
 
Collections in Java
Collections in JavaCollections in Java
Collections in Java
 

Andere mochten auch

Netherlands(Report)
Netherlands(Report)Netherlands(Report)
Netherlands(Report)
Terry Kao
 
Presentation3
Presentation3Presentation3
Presentation3
fm00001
 
reccebladet-13rätta
reccebladet-13rättareccebladet-13rätta
reccebladet-13rätta
Alexander K
 
CROATIA - a lifetime experience with Sailing Place _)
CROATIA - a lifetime experience with Sailing Place _)CROATIA - a lifetime experience with Sailing Place _)
CROATIA - a lifetime experience with Sailing Place _)
Andelo Zeravica
 

Andere mochten auch (11)

Find us on Facebook - Facebook jako narzędzie komunikacji marki
Find us on Facebook - Facebook jako narzędzie komunikacji markiFind us on Facebook - Facebook jako narzędzie komunikacji marki
Find us on Facebook - Facebook jako narzędzie komunikacji marki
 
Piquete Antibala
Piquete AntibalaPiquete Antibala
Piquete Antibala
 
Netherlands(Report)
Netherlands(Report)Netherlands(Report)
Netherlands(Report)
 
Presentation3
Presentation3Presentation3
Presentation3
 
reccebladet-13rätta
reccebladet-13rättareccebladet-13rätta
reccebladet-13rätta
 
10 key Story Questions
10 key Story Questions10 key Story Questions
10 key Story Questions
 
Plantilla de diseño
Plantilla de diseñoPlantilla de diseño
Plantilla de diseño
 
Enfasis en-los-procesos
Enfasis en-los-procesosEnfasis en-los-procesos
Enfasis en-los-procesos
 
Лечебное голодание. Презентация к лекции Лилии Горелой
Лечебное голодание. Презентация к лекции Лилии ГорелойЛечебное голодание. Презентация к лекции Лилии Горелой
Лечебное голодание. Презентация к лекции Лилии Горелой
 
CROATIA - a lifetime experience with Sailing Place _)
CROATIA - a lifetime experience with Sailing Place _)CROATIA - a lifetime experience with Sailing Place _)
CROATIA - a lifetime experience with Sailing Place _)
 
Ecological Agriculture
Ecological AgricultureEcological Agriculture
Ecological Agriculture
 

Ähnlich wie Java Databse Connectvity- Alex Jose (20)

Java 1-contd
Java 1-contdJava 1-contd
Java 1-contd
 
Scrollable Updatable
Scrollable UpdatableScrollable Updatable
Scrollable Updatable
 
Scrollable Updatable
Scrollable UpdatableScrollable Updatable
Scrollable Updatable
 
Executing Sql Commands
Executing Sql CommandsExecuting Sql Commands
Executing Sql Commands
 
Executing Sql Commands
Executing Sql CommandsExecuting Sql Commands
Executing Sql Commands
 
Jdbc[1]
Jdbc[1]Jdbc[1]
Jdbc[1]
 
JDBC programming
JDBC programmingJDBC programming
JDBC programming
 
Introduction to JDBC and database access in web applications
Introduction to JDBC and database access in web applicationsIntroduction to JDBC and database access in web applications
Introduction to JDBC and database access in web applications
 
Jdbc api
Jdbc apiJdbc api
Jdbc api
 
JDBC JAVA DATABASE CONNECTIVITY AND JAVA
JDBC JAVA DATABASE CONNECTIVITY AND JAVAJDBC JAVA DATABASE CONNECTIVITY AND JAVA
JDBC JAVA DATABASE CONNECTIVITY AND JAVA
 
Jdbc 1
Jdbc 1Jdbc 1
Jdbc 1
 
JDBC – Java Database Connectivity
JDBC – Java Database ConnectivityJDBC – Java Database Connectivity
JDBC – Java Database Connectivity
 
30 5 Database Jdbc
30 5 Database Jdbc30 5 Database Jdbc
30 5 Database Jdbc
 
spring-tutorial
spring-tutorialspring-tutorial
spring-tutorial
 
JDBC
JDBCJDBC
JDBC
 
3 database-jdbc(1)
3 database-jdbc(1)3 database-jdbc(1)
3 database-jdbc(1)
 
JDBC (2).ppt
JDBC (2).pptJDBC (2).ppt
JDBC (2).ppt
 
Jdbc ja
Jdbc jaJdbc ja
Jdbc ja
 
jdbc_presentation.ppt
jdbc_presentation.pptjdbc_presentation.ppt
jdbc_presentation.ppt
 
Java database connectivity
Java database connectivityJava database connectivity
Java database connectivity
 

Mehr von Dipayan Sarkar

why focus on adolescents unique needs
why focus on adolescents unique needswhy focus on adolescents unique needs
why focus on adolescents unique needs
Dipayan Sarkar
 
aep in india milestones, learning, way forward
aep in india milestones, learning, way forwardaep in india milestones, learning, way forward
aep in india milestones, learning, way forward
Dipayan Sarkar
 

Mehr von Dipayan Sarkar (18)

Relationships
RelationshipsRelationships
Relationships
 
ideal learning space
ideal learning spaceideal learning space
ideal learning space
 
introduction to aep arc
introduction to aep arcintroduction to aep arc
introduction to aep arc
 
why focus on adolescents unique needs
why focus on adolescents unique needswhy focus on adolescents unique needs
why focus on adolescents unique needs
 
aep in india milestones, learning, way forward
aep in india milestones, learning, way forwardaep in india milestones, learning, way forward
aep in india milestones, learning, way forward
 
Softskills - S Fernandez
Softskills - S FernandezSoftskills - S Fernandez
Softskills - S Fernandez
 
Project Based Learning- Ashish K Chaurdia
Project Based Learning- Ashish K ChaurdiaProject Based Learning- Ashish K Chaurdia
Project Based Learning- Ashish K Chaurdia
 
Linux and the Open Source- D Sarkar
Linux and the Open Source- D SarkarLinux and the Open Source- D Sarkar
Linux and the Open Source- D Sarkar
 
File Handling - N K Upadhyay
File Handling - N K UpadhyayFile Handling - N K Upadhyay
File Handling - N K Upadhyay
 
Sorting Techniques - Govardhan Satish
Sorting Techniques - Govardhan SatishSorting Techniques - Govardhan Satish
Sorting Techniques - Govardhan Satish
 
Application of Stack - Yadraj Meena
Application of Stack - Yadraj MeenaApplication of Stack - Yadraj Meena
Application of Stack - Yadraj Meena
 
Information Technology Act 2000 - Santosh K Pathak
Information Technology Act 2000 - Santosh K PathakInformation Technology Act 2000 - Santosh K Pathak
Information Technology Act 2000 - Santosh K Pathak
 
Universal Gates - Aneesa N Ali
Universal Gates - Aneesa N AliUniversal Gates - Aneesa N Ali
Universal Gates - Aneesa N Ali
 
Selection Sort - Vipin Ramola
Selection Sort - Vipin RamolaSelection Sort - Vipin Ramola
Selection Sort - Vipin Ramola
 
Deletion of a Record from a File - K Karun
Deletion of a Record from a File - K KarunDeletion of a Record from a File - K Karun
Deletion of a Record from a File - K Karun
 
Computer Viruses- B S Kalyan Chakravarthy
Computer Viruses- B S Kalyan ChakravarthyComputer Viruses- B S Kalyan Chakravarthy
Computer Viruses- B S Kalyan Chakravarthy
 
Cloud Computing- Sreehari S
Cloud Computing- Sreehari SCloud Computing- Sreehari S
Cloud Computing- Sreehari S
 
SQL JOINS- Reena P V
SQL JOINS- Reena P VSQL JOINS- Reena P V
SQL JOINS- Reena P V
 

Kürzlich hochgeladen

Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
KarakKing
 

Kürzlich hochgeladen (20)

Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 

Java Databse Connectvity- Alex Jose

  • 3.
  • 4.  DriverManager Class : It is the class used to load JDBC Driver needed to access particular database.  Connection class : It manages the connection and communication to the database.  Statement Class: It contains the string that are submitted to the database for execution. And it will execute the SQL statement.  ResultSet Class : If the statement class contains select statement, then during the execution it will return selected rows from the database are assigned to ResultSet and it contains the methods to move through the rows and get the values.
  • 5.
  • 6.  Step1. import packages required for Database Programming.  Step2. Register the JDBC Driver.  Open a connection.  Execute a Query.  Extract data from the ResultSet.  Cleanup the environment.
  • 7. DESIGN THE INTERFACE AS PER REQUIREMENT
  • 8.  1. Import the packages required for Database Programming  import java.sql.*;  2. Register the JDBC Driver with Java Program.  Class.forName(“java.sql.DriverManager");  3. Open the connection.  This requires using the DriverManager.getConnection() method to create a connection object, which represents the physical connection with the database. To connect to the database, we need complete URL to the database with userid and password of MySQL.
  • 9.
  • 10.
  • 11.  4. Execute a query.  We need to create an object of type Statement or PreparedStatement for building and submitting an SQL statement to the database using the createStatement() function of Connection class.  in the Statement class executeQuery() method is needed to execute select statement in SQL and executeUpdate() method is to execute DML statements.  if the SQL command is Select statement we need a class called ResultSet to store and process the records.  The Result set refers to a logical set of records that are fetched from the database by executing a query and made available to the application program.
  • 12.  next()  moves the cursor forward one  first()  to move to the firts row.  last()  move the cursor to the lat lasr row.  relative(int rows)  moves the cursor relative to the current position.  absolute(int rno)  position the cursor on the rno th rows in the ResultSet.  getRow()  to get the current cursor position.
  • 13. Extract data from ResultSet  ResultSet class has several methods to get the values from the columns from the rows pointed by the cursor.  getInt("FieldName");  getString("FieldName"); getString(fieldNumber);  getFloat("FieldName");  getDate("FieldName");  getLong("FieldName");.
  • 14.
  • 16.  DefaultTableModel dtm=(javax.swing.table.DefaultTableModel)studenttab.getModel();  int rows=dtm.getRowCount();  if(rows>0)  {  for(int i=0;i<rows;i++)  {  dtm.removeRow(0);  }  }  try  {  Class.forName("java.sql.DriverManager");  Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/mydbll“,"root","");  Statement stmt=con.createStatement();  String str="select * from student";  ResultSet rs=stmt.executeQuery(str);  while(rs.next())  {  int sid=rs.getInt("stdid");  String sname= rs.getString("stdname"); int mark= rs.getInt(“mark");  Object obj[]={sid,sname,mark};  dtm.addRow(obj);   }  }  catch(Exception e)  {  System.out.println(e);  }
  • 17.  Executing the select statement having criteria.  String str=”select * from student where stdid=”+ t1.getText;  String str=”select * from student where stsname=’ ” + tname.getText() +” ’ ”;   To Execute DML commands  Int sid=Integer.parseInt(t1.getText());  String sname= tname.getText();  Int mark=Integer.parseInt(tmark.getText());  String str=”insert into student values(“+ sid+” , ’ “ + sname +” ’ , “+ mark +”)”;  Stmt.executeUpdate(str);  String str=”delete * from student where stdid=” + t1.getText() +”)”;  Stmt.executeUpdate(str);   String str=”update student set mark =mark+5 where stdname=’ ” + tname.getText() +” ’ )”;  Stmt.executeUpdate(str);