资源简介
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
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 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
相关资源
- SSD7练习及答案
- ssd7 exercise10 答案 卡耐基 icarnegie
- 卡耐基 SSD7 exercise 10 答案
- endnoteX9中科大版
- EndnoteX9破解版,至今最好的破解版本
- EndNoteX9 汉化+原版_破解版安装包
- EndNodeX9破解版
- SSD7 所有习题答案完美版
- SSD7 练习10标准答案
- SSD7所有练习答案数据库系统
- SSD7所有答案SSD7所有答案
- ssd7 exercise5 老师给的答案
- ssd7 exercise10 完整答案
- ssd7 exercise7 完整答案
- ssd7 exam2 Practical + choice
- SSD7 选择题。Multiple-Choice
- SSD7 exercise5 答案
- 西工大ssd7所有答案
- ssd7的答案
- 卡耐基梅隆大学SSD7练习7答案——SS
- Programming with Transactions SSD7Programming
- SSD7 exercise6
- ssd7完整答案
- ssd7 exercise7
- ssd7-ex5-ER.gif
- 卡耐基 SSD7答案(全 exam+qiuz+excerise)
- EndNoteX9格式文件,Chinese Std GBT7714 (
评论
共有 条评论