0% found this document useful (0 votes)
9 views2 pages

Netbean JDBC Connectivity

netbean jdbc connectivity
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views2 pages

Netbean JDBC Connectivity

netbean jdbc connectivity
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

import java.sql.

*;

class Test2{

public static void main(String ar[]){

try{

Class.forName("com.mysql.jdbc.Driver");

Connection c=DriverManager.getConnection("jdbc:mysql://localhost:3306/studb","root","admin123");

Statement st=c.createStatement();

ResultSet rs=st.executeQuery("select * from studentinfo");

while(rs.next()){

System.out.println(rs.getString(1));

}catch(Exception ee)

{System.out.println(ee);}

}}

import java.sql.*;

class Test2{

public static void main(String ar[]){

try {

// loading thejdbc odbc driver

Class.forName("com.mysql.jdbc.Driver");

// creating connection toth data base

Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/studb","root","admin123");

Statement st = con.createStatement();

// create an execute sql command on database


ResultSet rs = st.executeQuery("Select * from studentinfo order by rollNo asc");

ResultSetMetaData rsmd = rs.getMetaData();

// this getColumnCount return the number of column in the selected table

int numberOfColumns = rsmd.getColumnCount();

// while loop and with while loop code use for print the data

while (rs.next()) {

for (int i = 1; i <= numberOfColumns; i++) {

if (i > 1)

System.out.print(", ");

String columnValue = rs.getString(i);

System.out.print(columnValue);

System.out.println("");

st.close();

con.close();

} catch (Exception ex) {

System.err.print("Exception: ");

System.err.println(ex.getMessage());

You might also like