-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathjdbcInsert.java
More file actions
30 lines (26 loc) · 1.06 KB
/
Copy pathjdbcInsert.java
File metadata and controls
30 lines (26 loc) · 1.06 KB
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
import java.sql.*;
/**
* JdbcInsert1.java - Demonstrates how to INSERT data into an SQL
* database using Java JDBC.
*/
class JdbcInsert1 {
public static void main(String[] args) {
try {
String url = "jdbc:msql://200.210.220.1:1114/Demo";
Connection conn = DriverManager.getConnection(url, "", "");
Statement st = conn.createStatement();
st.executeUpdate("INSERT INTO Customers " +
"VALUES (1001, 'Simpson', 'Mr.', 'Springfield', 2001)");
st.executeUpdate("INSERT INTO Customers " +
"VALUES (1002, 'McBeal', 'Ms.', 'Boston', 2004)");
st.executeUpdate("INSERT INTO Customers " +
"VALUES (1003, 'Flinstone', 'Mr.', 'Bedrock', 2003)");
st.executeUpdate("INSERT INTO Customers " +
"VALUES (1004, 'Cramden', 'Mr.', 'New York', 2001)");
conn.close();
} catch (Exception e) {
System.err.println("Got an exception! ");
System.err.println(e.getMessage());
}
}
}