Download 3.3 1221

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
EXPERIMENT 3.3
NAME: Manish Baldia
SECTION & GROUP:PH20BCS601-B
SEMESTER: 3
UID: 20BCS1221
SUBJECT: JAVA PROGRAMMING
Aim/Overview of the practical: Write a program to insert values in a table
at run time using JDBC.
Steps for experiment/practical/Code:
package abc;
import
import
import
import
java.sql.Connection;
java.sql.DriverManager;
java.sql.SQLException;
java.sql.Statement;
public class JDBCExample {
static final String DB_URL = "jdbc:mysql://localhost/TUTORIALSPOINT";
static final String USER = "guest";
static final String PASS = "guest123";
public static void main(String[] args) {
// Open a connection
try(Connection conn = DriverManager.getConnection(DB_URL, USER, PASS);
Statement stmt = conn.createStatement();
) {
// Execute a query
System.out.println("Inserting records into the table...");
String sql = "INSERT INTO Registration VALUES (100, 'Zara', 'Ali', 18)";
stmt.executeUpdate(sql);
sql = "INSERT INTO Registration VALUES (101, 'Mahnaz', 'Fatma', 25)";
stmt.executeUpdate(sql);
sql = "INSERT INTO Registration VALUES (102, 'Zaid', 'Khan', 30)";
stmt.executeUpdate(sql);
sql = "INSERT INTO Registration VALUES(103, 'Sumit', 'Mittal', 28)";
stmt.executeUpdate(sql);
}
}
System.out.println("Inserted records into the table...");
} catch (SQLException e)
{ e.printStackTrace();
}
import
import
import
import
java.sql.Connection;
java.sql.DriverManager;
java.sql.SQLException;
java.sql.Statement;
public class JDBCExample
{ static final String DB_URL
=
"jdbc:mysql://localhost/TUTORIALSPOINT";
static final String USER = "guest";
static final String PASS = "guest123";
public static void main(String[] args) {
// Open a connection
try(Connection conn = DriverManager.getConnection(DB_URL,
USER, PASS);
Statement stmt = conn.createStatement();
) {
// Execute a query
System.out.println("Inserting records into the
table...");
String sql = "INSERT INTO Registration VALUES (100,
'Zara', 'Ali', 18)";
stmt.executeUpdate(sql);
sql = "INSERT INTO Registration VALUES (101, 'Mahnaz',
'Fatma', 25)";
stmt.executeUpdate(sql);
sql = "INSERT INTO Registration VALUES (102, 'Zaid',
'Khan', 30)";
stmt.executeUpdate(sql);
sql = "INSERT INTO Registration VALUES(103, 'Sumit',
'Mittal', 28)";
stmt.executeUpdate(sql);
System.out.println("Inserted records into the table...");
}
}
} catch (SQLException e)
{ e.printStackTrace();
}
Result/Output/Writing Summary:
Learning outcomes (What I have learnt):
1. About the concepts and understanding of JDBC.
2. Implementation of JDBC in JAVA.
Evaluation Grid (To be created as per the SOP and Assessment guidelines by the faculty):
Sr. No.
Parameters
Marks Obtained
Maximum Marks
1.
2.
3.
Related documents