



























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




























String sql = "CREATE DATABASE UIIT"; stmt.executeUpdate(sql); System.out.println("Database created successfully..."); }catch(SQLException se){ se.printStackTrace(); }catch(Exception e){ e.printStackTrace(); }finally{ try{ if(stmt!=null) stmt.close(); }catch(SQLException se2){ se2.printStackTrace(); } try{ if(conn!=null) conn.close(); }catch(SQLException se3){ se3.printStackTrace(); } } System.out.println("All resources closed"); } }
PRACTICAL โ 02
import java.sql.*; public class CreateTableJDBC { static final String JDBC_DRIVER = "com.mysql.cj.jdbc.Driver"; static final String DB_URL = "jdbc:mysql://localhost/UIIT"; static final String USER = "mogambo"; static final String PASS = "Qwerty@1234"; public static void main(String args[]){ Connection conn = null; Statement stmt = null; try{ Class.forName(JDBC_DRIVER); System.out.println("Connecting to selected database..."); conn = DriverManager.getConnection(DB_URL, USER, PASS);
conn.close(); }catch(SQLException se3){ se3.printStackTrace(); } } System.out.println("All resources closed"); } }
PRACTICAL โ 03
import java.sql.*; public class InsertDataJDBC { static final String JDBC_DRIVER = "com.mysql.cj.jdbc.Driver"; static final String DB_URL = "jdbc:mysql://localhost/UIIT"; static final String USER = "mogambo"; static final String PASS = "Qwerty@1234"; public static void main(String args[]){ Connection conn = null; Statement stmt = null; try{ Class.forName(JDBC_DRIVER); System.out.println("Connecting to selected database..."); conn = DriverManager.getConnection(DB_URL, USER, PASS);
System.out.print("Roll No.: "+roll_num); System.out.print(", Age: "+age); System.out.print(", First Name: "+first_name); System.out.println(", Last Name: "+last_name); } rs.close(); }catch(SQLException se){ se.printStackTrace(); }catch(Exception e){ e.printStackTrace(); }finally{ try{ if(stmt!=null) stmt.close(); }catch(SQLException se2){ se2.printStackTrace(); } try{ if(conn!=null) conn.close(); }catch(SQLException se3){ se3.printStackTrace(); } } System.out.println("All resources closed"); } }
PRACTICAL โ 04
import java.sql.*; public class DeleteDataJDBC { static final String JDBC_DRIVER = "com.mysql.cj.jdbc.Driver"; static final String DB_URL = "jdbc:mysql://localhost/UIIT"; static final String USER = "mogambo"; static final String PASS = "Qwerty@1234"; public static void main(String args[]){ Connection conn = null; Statement stmt = null; try{ Class.forName(JDBC_DRIVER); System.out.println("Connecting to selected database..."); conn = DriverManager.getConnection(DB_URL, USER, PASS);