How do you create Connection?

Answer Posted / vikky jain

i think the one of easiest way to create a connection is
that we have to perform following steps

1. we have to define what is driver name, url address of
database , user name and password of database .
like it

String driverName = "com.mysql.jdbc.Driver";
String url ="jdbc:mysql://localhost:3309/test";
String userid ="root";
String password ="1234";


after it we have to load drivers whatever name we given above
//driver loading
Class.forName(driverName);


after loading drivers we need to get the connection by using
this

con = DriverManager.getConnection(url, userid, password);

if value of con is not null then connection has been created
where con is an object of Connection class.
if the value is null it means that there may be some
trouble in database connectivity so it may throw an error
named SQLException

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are the main steps in java to make JDBC connectivity?

787


Why do we need jdbc?

792


What is the difference between client and server database cursors?

808


Which is faster jdbc or odbc?

678


What is meant by connection string?

721


What are collection pools?

711


If you are truncated using JDBC, how can you that how much data is truncated?

801


What does executeupdate return in java?

716


Why is jdbc used?

696


What is the different between ResultSet and RowSet?

724


What class.forname will do while loading drivers of jdbc?

682


What is jdbc stand for?

694


How to insert an image or raw data into database?

739


How many types of jdbc drivers are there?

739


What is jdbc template?

731