import java io InputStream import java io Reader import java math BigD

 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import java.io.InputStream;
import java.io.Reader;
import java.math.BigDecimal;
import java.net.URL;
import java.sql.*;
import java.util.Calendar;
/**
* Created with IntelliJ IDEA.
* User: hunter
* Date: 06.04.15
* Time: 11:34
* To change this template use File | Settings | File Templates.
*/
public class Client{
public static void main(String s[]){
Connection connection = null;
try {
connection = DriverManager.getConnection(
"jdbc:oracle:thin:@localhost:1521:xe", "tolya1",
"123456");
String sql = "CREATE TABLE Person(" +
"name VARCHAR(20) NOT NULL, " +
"telephone VARCHAR(20) NOT NULL " +
")";
Statement stmt = connection.createStatement();
PreparedStatement ps = connection.prepareStatement(sql);
ps.execute();
stmt = connection.createStatement();
ps = connection.prepareStatement("INSERT INTO Person (name, telephone) VALUES (?, ?)");
ps.setString(1,"Temp");
ps.setString(2,"0993812832");
ps.execute();
//stmt = connection.createStatement();
ps = connection.prepareStatement("UPDATE Person SET name = ? WHERE name = 'Temp'");
ps.setString(1,"Tolya");
ps.execute();
//stmt = connection.createStatement();
ResultSet rset = stmt.executeQuery("SELECT * FROM Person");
while (rset.next())
System.out.println(rset.getString("name")+ " : " + rset.getString("telephone"));
stmt.close();
// stmt = connection.createStatement();
ps = connection.prepareStatement("DELETE Person WHERE name = ?");
ps.setString(1,"Tolya");
ps.execute();
//stmt = connection.createStatement();
ps = connection.prepareStatement("DROP TABLE Person") ;
ps.executeUpdate();
} catch (SQLException e) {
System.out.println(e.getMessage());
}
}
}