-
Notifications
You must be signed in to change notification settings - Fork 4
/
JDBCPrepare10.java
37 lines (30 loc) · 1.02 KB
/
JDBCPrepare10.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/*
A JDBC program using prepared Statement
*/
import java.sql.*;
public class JDBCPrepare10 {
public static void main(String[] args){
try{
//Load Driver
Class.forName("oracle.jdbc.OracleDriver");
//Make Connection
Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","username","password");
//query
String query = "insert into author values(?,?,?)";
// Prepared Statement
PreparedStatement pst = conn.prepareStatement(query);
//Fire Query
pst.setInt(1,5);
pst.setString(2, "MNO");
pst.setInt(3,933847628);
pst.execute();
//pst.execute("update author set Phone = 9382736453 where id=5");
//Close
pst.close();
conn.close();
}
catch(Exception e){
System.out.println(e.getMessage());
}
}
}