Name: ________________________________________________________________
UD Email: _____________________________________________@ udel.edu
About this exam
A hint about allocating your time:
How to get a good grade:
1 | 2 | 3 | 4 | 5 | 6 |
(25 pts) Below are two ways that one could do a query in JDBC.
Both have been tested, and correctly return the result set.
Explain as clearly as possible which way is preferred, and precisely why.
// Create a statement for SQL queries try { myStmt = myCon.createStatement(); } catch (Exception e){ e.printStackTrace(); return brands; } // Set up the query. String tableName = prefix_ + "Beers"; String query = "SELECT beer, color FROM " + tableName + " WHERE color='" + color + "'"; ResultSet rs; try { rs = myStmt.executeQuery(query); } catch (Exception e) { e.printStackTrace(); return brands; }
// Set up the query. String tableName = prefix_ + "Beers"; String query = "SELECT beer, color FROM " + tableName + " WHERE color=?"; // Stick the value of "color" in where the first ? appears, and exec the query ResultSet rs; try { PreparedStatement prepStmt = myCon.prepareStatement(query); prepStmt.setString(1, color); rs = prepStmt.executeQuery(); } catch (Exception e) { e.printStackTrace(); return brands; }
(25 pts) The following lines of code appear in the H09 example program
String jdbcURL = getServletContext().getInitParameter("jdbcURL"); String mySQLuser = getServletContext().getInitParameter("mySQLuser"); String mySQLpw = getServletContext().getInitParameter("mySQLpw");
Answer the following questions about these lines of code:
jdbc:mysql://cisc474.acad.cis.udel.edu/pconrad, pconrad
, and 97s8d9f7s
, respectively?
(25 pts) In homework H03, and homework H05, you were asked to validate your web pages using validator.w3.org. Briefly explain what validation is. In your answer, include the following points:
Debugging is an important skill in working with web applications. Debugging techniques will vary from technology to technology, but we've learned some specific ones relating to working with Tomcat and SQL.
Suppose you find that when you access a screen in your web app that you "know" should produce a particular result—for example a list of all the "dark beers" in your database—but instead, you get an empty list.
(5 pts) What can you do to make sure that the database itself is set up properly (independent of the web app)?
(5 pts) Where (specifically) can you look to see if there is a stack trace being generated by some run time error deep inside your web app?
(5 pts) Suppose you suspect that an error is your model class is causing the problem. You make a change and recompile. But nothing changes. So you suspect that perhaps your changes are "not taking"—that there is perhaps a mismatch between the code actually running on the server, and the code that you are looking at in your editor.
What can you do to make absolutely sure that the code running on the Tomcat server is actually the same as the source code you are looking? (Don't just say "redeploy", or stop and restart the server—I want something even more specific and foolproof—I want close to 100% certainty!)
(5 pts) Suppose you are using a build.xml file similar to the build.xml file supplied with H08 and H09. Is it sufficient, after each time you make a change, to just run ant compile?
How about ant create-war
? Explain.
(5 pts) Describe at least one other useful Java/SQL/Ant/Tomcat debugging technique, or a problem and its solution.
By other, I mean describe one that is different from the ones you've referred to so far in your answer to this question.
(25 pts) In both Chapter 1 and Chapter 3 of your textbook, the text recommends a clean separation between a development environment, and a deployment environment. Explain why. In your answer, include:
(25 pts) Albert Einstein is often quoted as having said: You do not really understand something unless you can explain it to your grandmother. This question is in that spirit.
Your friend “Chris” has asked for your help. Chris is a smart businessman, but is not particularly tech-savvy. Chris wants to hire someone to do some maintenance on the web site for his company. He knows that the current site is based on “JSPs” but he doesn't’t really know what those are. He tried to hire you, but your work load is too much at the moment; you know you don’t really have time to help him out. However, you do agree to sit in on the interviews of the web developers who have applied for the job.
The first person to apply has a really nice looking portfolio. The web sites he says he developed look great. Your friend is very impressed as he looks through the sites the candidate shows him. So, your friend asks you if you have any questions for the candidate. You start with an easy one, just to break the ice: “Tell me, how did you learn HTML?”
He says, “well, to be honest, I never took a formal class. I just did a ‘view source’ on a bunch of web pages that I thought looked good, and sort of figured out how they worked, and picked up HTML that way. As you can see, my web pages look pretty snazzy, even though I never took a formal class. Here see, you can do ’view source’ on any web page and read how it is coded.” At this the candidate shows a view source, and shows your friend how the tags line up with some of the elements on the rendered page. Your friend is getting more and more impressed.
You : “Very clever. Tell me though, my friend also needs someone who can maintain Java Server Pages—you know, JSPs. You've shown us a bunch of JSP based sites as part of your portfolio. Did you create those sites too?”
The candidate: “Yes, I sure did.”
You: "How did you learn JSP?
Candidate: "Exactly the same way— just found a bunch of sites that used JSPs, and then did “view source” and figured out they worked.”
You: “Really? You learned not just static HTML, but also JSPs by doing ’view source’? Are you sure?”
Candidate: “Yup, sure did. Took me a while to figure it out the JSP part, but eventually I got it.”
You “Ah, very good—well I think that’s all we need to know.”
Your friend is all smiles, and you and he both thank the candidate for stopping by. Once the candidate leaves the room, you turn to your friend and say: “That candidate is a bald faced liar, and technically incompetent. Under no circumstances should you hire him.”
Your friend is taken aback. “That’s a pretty serious charge. How do you know this after only asking him four questions?” What do you tell your friend?
Note: If you understand how JSPs work, it pretty simple to work out that the candidate is lying, and furthermore that he is not technically competent enough to realize that the lie is easy to spot. However, for this question, a quick explanation in technical terms is NOT sufficient for full credit. Having the technical facts correct will only earn you half the points.
For full credit, you will be graded not only on the technical content of your question, but how well you explain it in terms that a non-technical person can understand. Keep in mind that your friend won't understand terms like "compiler", "container", "source code", "Tomcat", etc. You friend isn't stupid—he's a very successful businessman. But you won't communicate with him if you talk in "geek speak". And it is important that he fully understands—“trust me, I'm an expert” is not going to cut it here.
Let's assume, to make things easier, that your friend did take one computer class in programming in
BASIC a zillion years ago, and vaguely remembers things like a “for loop” and “input” and “output”.
So you can use that as a point of reference. He's also seen the HTML code— the candidate did a view
source, and showed him how the tags like <table>
correspond with the table on the page. He also
understands that a computer has files on it, and that the files are stored on the hard disk. He sort of
gets, too, that information on web pages comes from some place called a “server” out there on the
network somehow, and makes its way to his computer, though he is very hazy on the details.