Establishing connection with the database
A free video tutorial from Abhay Redkar
4.3 instructor rating • 7 courses • 24,681 students
Learn more from the full courseJava JDBC with Oracle: Build a CRUD Application
Learn all core JDBC concepts and build a CRUD application.
01:58:52 of on-demand video • Updated December 2018
- Learn all core JDBC concepts.
- Build Java database applications
English [Auto] Hi everyone. Welcome back. So in this world we are going to establish a connection with that Oracle database. Now we've already seen the connectivity steps before. So out of those five connectivity steps we're going to implement the first two steps in this tutorial. Now before we begin the actual coding there are just a few things we need to tell you. So I'm using the eclipse for coding and internet. I've already created a project by the name busy and it's that I've created a JVC S-Class. OK. So we're going to write all our code in said this. Judy B.C.E. test class. OK. Search Strogoff. Now the first thing which I'm going to do is just print a statement on the screen OK which is connecting to the read abbes. So this will just mark the start of our application. OK. Now the first step is Lord and register the driver. So for that we had the statement glass for name and inside that we passed the Oracle driver last name. OK. So this is the last name of the Oracle driver. Right. And we are getting some error over here. And it is asking us to handle this statement. So I just surround it with a try catch block. OK. So I'm writing a try catch and the error is gone right now. So this was the first step. OK. So this will load and register that driver. Now step two is creating a connection. So this is how we create a connection. We use the get connection method of the driver manager class. Right. And we've already seen what these things are. But I'll still raise them one more time. So the get connection method it takes three parameters. The first parameter is the connection you idle. The second part emitter is the user name and the last battery window is the password. So I see the connection you idle again. So all we see is the API. Oracle is that it is then is a type of JEDEC driver local host is the server on which Oracle is running. One five to one is the port number and SC is the name of the Oracle service. Then the second part emitter is the user name which is system so system is the default user name for Oracle database. And finally the last Baramidze is the password. And what I have done is I've kept the same name for the password. OK. As the username. OK but you can keep any password which you want. OK. So while installing Oracle just remember the password you enter right and the same password you have to enter or when you're good. So this is how we create a connection. And as you can see we are getting some error here and that is because we have not imported these classes. So I just write one more statement which is in for John Edward Escurial don't start. So this will just import all the GBC related classes. Right. And the error is gone. So after this I'll just print one more statement which is connection established. Right. So if everything goes fine then this statement should be displayed. OK. So let's see if and run the program now for running. We have a button over here. So I just click it. And as you can see we are getting some error and it is saying class not found exception. So it is not able to find the actual driver class and that is because we have not imported the Oracle driver. OK so before starting we have to import the Oracle driver justified. Right. So for doing that just right click on the project go to properties go to job well but then click on the library's tab and then click add extra jar. OK. Now I've already downloaded that job. So I just have to import it. OK. So this is the Oracle driver job right. So I'll just click on apply and. OK. So let's try and run this one more time and this time it should print connection established. And yes as you can see the connection with the database is established. So this jar file you will find it on the official website you can check it over here. OK. So this was the in which I have downloaded. Right. So yes that is that's it for now. Thank you for watching and see you in my next tutorial.