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

How to invoke Oracle Stored Procedure with Database Objects as IN/OUT?

585


What does executeupdate return in jdbc?

515


Why prepared statements are faster?

533


How do you insert images into database using jdbc?

570


Describe how the jdbc application works.

528






What is the fastest type of JDBC driver?

599


What is db client?

499


What are the utilities of the callablestatement?

522


What are the advantages of using preparedstatement in java?

549


What is addbatch jdbc?

539


How can I create a custom RowSetMetaData object from scratch?

551


Explain the locking system in jdbc?

548


What is type 4 jdbc driver?

488


What are the different types of interfaces in the api component?

525


What is jdbc and odbc?

512