0% found this document useful (0 votes)
2 views1 page

JDBC InitialProgram

The document provides a Java code snippet for connecting to a MySQL database and retrieving data from a 'student' table. It includes steps for loading the JDBC driver, establishing a connection, creating a statement, executing a query, and processing the result set. Error handling is also implemented to catch exceptions during the database operations.

Uploaded by

sridatri.oisv
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views1 page

JDBC InitialProgram

The document provides a Java code snippet for connecting to a MySQL database and retrieving data from a 'student' table. It includes steps for loading the JDBC driver, establishing a connection, creating a statement, executing a query, and processing the result set. Error handling is also implemented to catch exceptions during the database operations.

Uploaded by

sridatri.oisv
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Prerequisite: Creation of database and table must be done with some data in

the table.

import [Link].*;  Importing the package

public class dbcon{

public static void main(String[] args) {

try {

[Link]("[Link]");  Load the Driver

Connection con =
[Link]("jdbc:mysql://localhost:3306/testdb","root",
"password"); Establishing the connection

Statement stmt = [Link]();  creating the statement

ResultSet rs = [Link]("SELECT * FROM student");  Execute


Query
while([Link]()){

[Link]([Link](1)+" "+[Link](2)+" "+[Link](3));

}  Process the result


[Link]();  Close the connection
} catch(Exception e){

[Link](e);

You might also like