-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTestDB.java
More file actions
42 lines (35 loc) · 1.12 KB
/
Copy pathTestDB.java
File metadata and controls
42 lines (35 loc) · 1.12 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
31
32
33
34
35
36
37
38
39
40
41
42
package ch24;
import java.io.File;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
/**
Tests a database installation by creating and querying
a sample table. Call this program as
java -classpath driver_class_path;. TestDB propertiesFile
*/
public class TestDB
{
public static void main(String[] args) throws Exception
{
if (args.length == 0)
{
System.out.println(
"Usage: java -classpath driver_class_path"
+ File.pathSeparator
+ ". TestDB propertiesFile");
return;
}
SimpleDataSource.init(args[0]);
try (Connection conn = SimpleDataSource.getConnection())
{
Statement stat = conn.createStatement();
stat.execute("CREATE TABLE Test (Name VARCHAR(20))");
stat.execute("INSERT INTO Test VALUES ('Romeo')");
ResultSet result = stat.executeQuery("SELECT * FROM Test");
result.next();
System.out.println(result.getString("Name"));
stat.execute("DROP TABLE Test");
}
}
}