資源簡(jiǎn)介
ICarnegie SSD7 Exercise 9 Solution

代碼片段和文件信息
import?java.util.*;
import?java.io.*;
import?java.text.*;
import?java.sql.*;
/**
?*?A?class?representing?the?driver?program?to?the
?*?SSD7?transaction?exercise.
?*
?*?@author?Abdibaeva?Gauhar
?*?@version?1.0.1
?*/
public?class?MovieTransaction
{
????/**
?????*?main?method.
?????*
?????*/
????public?static?void?main(?String?[]?args?)
????{
String?[]?movienames?=?new?String[10];
String?[]?movietimes?=?new?String[10];
String?sqlquery?=?null;
String?moviename?=?null;
String?movietime?=?null;
ResultSet?rset?=?null;
Connection?conn?=?null;
Statement?stmt?=?null;
BufferedReader?keyIn?=?null;
String?url?=?“jdbc:postgresql:movie“;
String?username?=?“webuser“;
String?password?=?“webuser“;
int?position?=?0?choice?movie_id?numseats?availableseats;
try
????{
//?Create?a?BufferedReader?to?read?input?from?the?keyboard.
keyIn?=?new?BufferedReader(new?InputStreamReader(System.in));
//?Load?the?PostgreSQL?JDBC?driver
Class.forName(“org.postgresql.Driver“);
//?Create?a?connection?to?the?database.
conn?=?DriverManager.getConnection(?url?usernamepassword?);
//?Create?a?statement?object.
stmt?=?conn.createStatement();
//?Begin?a?new?chained?transaction.
stmt.executeUpdate(?“Begin?Work“?);
//?Set?the?transaction?isolation?level?to?serializable
stmt.executeUpdate(?“set?transaction?isolation?level?serializable“?);
System.out.println(?“Welcome?to?the?movie?theater!“?);
//?Query?the?titles?currently?playing.
String?SQLQuery?=?“select?distinct?title?from?movie“;
rset?=?stmt.executeQuery(?SQLQuery?);
while(?rset.next()?)
????{
movienames[rset.getRow()]?=?rset.getString(?“title“?);
System.out.println(?rset.getRow()?+?“:?“?+?rset.getString(“title“)?);
????}
//?Ask?the?user?what?movie?he?wants?to?see.
System.out.print(?“Enter?the?number?of?the?movie?you?want?to?see:“?);
choice?=?Integer.parseInt(keyIn.readLine());
moviename?=?movienames[(choice)];
//?Query?the?id?for?this?movie.
sqlquery?=?new?String(?“select?movie_id?from?movie?where?title=‘“?+?moviename?+?“‘“?);
rset?=?stmt.executeQuery(?sqlquery?);
rset.next();
movie_id?=?rset.getInt(?“movie_id“?);
//?Query?the?available?times?for?the?chosen?movie.
sqlquery?=?new?String(?“select?distinct?movie_time?from?showing?where?movie_id?=“?+?movie_id?);
rset?=?stmt.executeQuery(?sqlquery?);
while(rset.next()){
????????????????????movietimes[(rset.getRow())]?=?rset.getString(?“movie_time“?);
????????????????????System.out.println(?rset.getRow()?+?“:?“?+?rset.getString(?“movie_time“?)?);
????????????????}
//?Ask?the?user?what?showing?he?wants?to?see.
System.out.println(?“Enter?the?number?of?the?time?you?want?to?see:?“?);
choice?=?Integer.parseInt(?keyIn.readLine()?);
movietime?=?movietimes[(choice)];
//?Ask?the?user?how?many?seats?he?wants.
System.out.println(?“Please?enter?the?number?of?seats?that?you?want?to?buy:?“?);
numse
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????文件??????56832??2013-11-17?21:53??Application.doc
?????文件???????1190??2013-11-16?22:04??deadlock.txt
?????文件???????1342??2013-11-16?19:16??isolation.txt
?????文件???????5062??2013-11-17?20:26??MovieTransaction.java
?????文件????????503??2013-11-11?09:28??rollback.txt
-----------?---------??----------?-----??----
????????????????64929????????????????????5
評(píng)論
共有 條評(píng)論