Java Reference
In-Depth Information
Display 19.13
Retrieving Rows with the SELECT Statement (part 3 of 3)
59 rs.close();
60 Conn.close();
61 }
62 catch (SQLException err)
63 {
64 System.err.println("SQL error.");
65 err.printStackTrace(System.err);
66 System.exit(0);
67 }
68 }
69 }
Sample Dialogue
Loaded the embedded driver.
Connecting to the database.
Connected.
All rows:
ID = 1, Author = Adams, Douglas, URL = http://www.douglasadams.com
ID = 2, Author = Simmons, Dan, URL = http://www.dansimmons.com
ID = 3, Author = Stephenson, Neal, URL = http://www.nealstephenson.com
All rows with an ID > 1:
ID = 2, Author = Simmons, Dan, URL = http://www.dansimmons.com
ID = 3, Author = Stephenson, Neal, URL = http://www.nealstephenson.com
Display 19.14
Updating Rows with the UPDATE Statement (part 1 of 3)
The database must be created
(Display 19.12) before running
this program. Use the program
in Display 19.13 to view the
changes made by this program.
1 import java.sql.Connection;
2 import java.sql.DriverManager;
3 import java.sql.ResultSet;
4 import java.sql.SQLException;
5 import java.sql.Statement;
6 import java.util.Scanner;
7 public class UpdateDB
8 {
9 private static final String driver =
"org.apache.derby.jdbc.EmbeddedDriver";
10 private static final String protocol = "jdbc:derby:";
(continued)
 
 
Search WWH ::




Custom Search