0% found this document useful (0 votes)
246 views

Practical 19

1. The program code writes a Java program that connects to a MySQL database called msbte, updates a row in the student table by changing the name and roll number where the roll number is equal to 2, and prints the student data before and after the update. 2. The program code contains two exercises - the first develops a JDBC program to retrieve data from a database table using ResultSet, and the second develops a program to update a record in a database table. The output sections are empty.

Uploaded by

Sam Mercy
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
246 views

Practical 19

1. The program code writes a Java program that connects to a MySQL database called msbte, updates a row in the student table by changing the name and roll number where the roll number is equal to 2, and prints the student data before and after the update. 2. The program code contains two exercises - the first develops a JDBC program to retrieve data from a database table using ResultSet, and the second develops a program to update a record in a database table. The output sections are empty.

Uploaded by

Sam Mercy
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Practical 19

Program code

1.Write a program to update a row to student table from MSBTE database using
Mysql 5.5 a database server

import java..sql.*;

class practical19_programcode_1

public static void main(String args[])

try

Class.forName(“com.mysql.cj.jdbc.Driver”);

Connection
cn=DriverManager.getConnection(“jdbc:mysql://localhot:3306/msbte”,”root”,”
sit@123”);

Statement stmt=con.createStatement();

Result rs=stmt.executeQuery(“Select*from student”)

While(rs.next())

System.out.println(rs.getInt(1)+ “ ” +rs.getstring(2));

int result=stmt.executeUpdate(‘update student set s_name=”xyz”,s_roll=3 where


s_roll=2”);

System.out.println(“After Update: “+result);

Result rs2=stmt.executeQuery(“Select * from student”);

While(rs2.next())

System.out.println(rs2.getInt(1)+ “ ”+rs2.getString(2));
Con.close();

Catch(Exception e)

System.out.println(e);

Output:

2. Write output of following JDBC code.


Exercise:

1.Develop a JDBC program to retrieve data using ResultSet.


import java.sql.*;
Class updatepr19
{
public static void main (String args[])throws
Exception
{
Class.forName(“com.mysql.cj.jdbc.Driver”);
Connection con=Drivermanager.getConnection(“jdbc;
mysql://localhost:33061mydb”,”root”,”sit@123”);
Statement stml=con.createstatement();
Stmt.executeupdate(“updatesit set name=’Sakshi’,address=’1at’ where
roll_no=(“ ”);
Con.close();
}
}
Output:

2. Develop a program to update a record in database table.


import java.sql.*;
class mysqlcon{
public static void main(String args[]){
Try{
Class.forName(“com.mysql.cj.jdbc.connection
con=Drivermanager.getconnection(”jdbc:mysql://localhost:3306/mydb”,”root”,
”sit@123”);
Statement stmt=stmt.con.createstatement();
Result rs=stmt.executequery(“select +form stud”);
While(rs.next())
System.out.println(rs.getInt(1)+” ”+rs.getString(2)+” ”+rs.getString(3));
con.close();
}
Catch(exceotion e)
{
System.out.println(e)
}
}
}
Output:

You might also like