This post originated from an RSS feed registered with Java Buzz
by Anthony Eden.
Original Post: Article Quality on Java.Net
Feed Title: All Things
Feed URL: http://allthings.mp/
Feed Description: Blogging about Java, Python, technology and generally anything which is of interest to me.
<html>
<head>
<title>Accessing data in a database</title>
</head>
<body>
<%
try {
// Step 1. Load the JDBC driver
Class.forName("org.gjt.mm.mysql.Driver");
// Step 2. Create a Connection object
Connection con = DriverManager.getConnection(
"jdbc:mysql///xeon/CompanySecret",
"budi", "secret");
System.out.println("got connection");
// Step 3. Create a Statement object and call its executeUpdate
// method to insert a record
Statement s = con.createStatement();
String sql =
"INSERT INTO Users VALUES ('Michael', 'Franks', '12/12/2003', 'm')";
s.executeUpdate(sql);
// Step 4. Use the same Statement object to obtain a ResultSet object
sql = "SELECT FirstName, LastName FROM Users";
ResultSet rs = s.executeQuery(sql);
while (rs.next()) {
out.println(rs.getString(1) + " " + rs.getString(2) + "<br>");
}
rs.close();
s.close();
con.close();
}
catch (ClassNotFoundException e1) {
// JDBC driver class not found, print error message to the console
System.out.println(e1.toString());
}
catch (SQLException e2) {
// Exception when executing java.sql related commands, print error message to the console
System.out.println(e2.toString());
}
catch (Exception e3) {
// other unexpected exception, print error message to the console
System.out.println(e3.toString());
}
%>
</body>
</html>
Why oh why would anyone publish an example like this today? OK, I know the answer: it is supposed to demonstrate to non-Java programmers (read VB programmers) how they can access a database from JSP. It is only an example right? But see that is where the problem is: if I am a new developer coming from another language and I see this type of coding then I will probably assume right away that this is the way JSPs should be written. Never mind the fact that all of that code could probably be reduced to one or taglib calls. Even though I don't use JSPs myself anymore I would still never demonstrate an example with this type of code. As a matter of fact why is there any reference to JSPs in the first place, why not just have the example written as a small command line application which outputs data to System.out? Heck, the title even mentions servlets although I don't see a single thing about servlets in the article.
So, after all of that, here's the point: articles which are going to be posted on java.net, a site which is sanctioned by Sun, had better be superb in all aspects, otherwise the effect of java.net will be more negative than positive.
Yes I am being hard on java.net. They have a responsibility to the developer community to produce the highest-quality content available because they can do the most damage.