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

exam

The Java program connects to a MySQL database and retrieves records from the 'S19' table. It includes commented-out code for creating the table, inserting, updating, and deleting records. The program prints the names and roll numbers of the entries in the table to the console.
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)
4 views1 page

exam

The Java program connects to a MySQL database and retrieves records from the 'S19' table. It includes commented-out code for creating the table, inserting, updating, and deleting records. The program prints the names and roll numbers of the entries in the table to the console.
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/ 1

import java.sql.

Connection;
import java.sql.ResultSet;
import java.sql.DriverManager;
import java.sql.Statement;
import java.sql.SQLException;
public class E1
{
private static final String URL="jdbc:mysql://localhost:3306/atharva1";
private static final String USER="root";
private static final String PASSWORD="root";
public static void main(String args[])
{
try
{
Connection con=DriverManager.getConnection(URL,USER,PASSWORD);
System.out.println("con suc");
Statement stmt=con.createStatement();
/* String ct="CREATE TABLE IF NOT EXISTS S19(name VARCHAR(20),roll INT(20))";
stmt.executeUpdate(ct);
System.out.println("Table created");
String it="INSERT INTO S19(name,roll) VALUES('atharva',19),('Siddhi',03),('ritik',10)";
stmt.executeUpdate(it);
System.out.println("value inserted");
String ut="UPDATE S19 SET name='Archu' WHERE roll=10";
stmt.executeUpdate(ut);
System.out.println("Table updated");
String dt="DELETE FROM S19 WHERE roll=19";
stmt.executeUpdate(dt);
System.out.println("rec deleted"); */
ResultSet r=stmt.executeQuery("Select *from S19");
while(r.next())
{
int rollno=r.getInt("roll");
String name=r.getString("name");
System.out.println("name: "+name+"Roll no: "+rollno);
}
}
catch(Exception e)
{
System.out.println(e);
}
}
}

You might also like