Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This assignment will use the “Chapter 2” source code you downloaded and installe

ID: 3681663 • Letter: T

Question

This assignment will use the “Chapter 2” source code you downloaded and installed IntelliJ and Tomcat and have them working together. If you have not already done so, you must have this running before you start this assignment. Everything you need to do this assignment you will have covered in your readings so it's just a matter of putting things together and get them working. Your assignment is to create a table that displays the following six columns of generated data: Locale, Current date and time in Locale format, Randomly generated current amount in the Locale currency, Greeting in the Locale language, Inquiry in the Locale language, Farewell in the Locale language. Your resultant table should resemble something like the following table:

Implement the table using JSTL with a properties file for the Greeting, Inquiry and Farewell values. Implement the table using a Java Bean to generate the table values including the ones that were in the properties file. You can find the wrox.com code downloads for this chapter http://www.wrox.com/go/projavaforwebapps on the Download Code tab.

Explanation / Answer

public class TableBeanMapping { public static void generateBean(String folderName) { try { Connection connection = OracleJDBC.GetConnection(); ColumnDatatypeMapping cdm; String sqlSelectTableName = "SELECT TABLE_NAME FROM USER_TABLES"; PreparedStatement psSelectTable = connection.prepareStatement(sqlSelectTableName); ResultSet rsTable = psSelectTable.executeQuery(); String tableName; while (rsTable.next()) { cdm = new ColumnDatatypeMapping(); tableName = rsTable.getString("TABLE_NAME"); String sqlSelectColumn = "SELECT COLUMN_NAME _ FROM COLS WHERE TABLE_NAME='" + tableName + "'"; PreparedStatement psSelectColumn = connection.prepareStatement(sqlSelectColumn); ResultSet rsColumn = psSelectColumn.executeQuery(); String columnName; while (rsColumn.next()) { columnName = rsColumn.getString("COLUMN_NAME"); String sqlSelectDatatype = "SELECT DATA_TYPE _ FROM COLS WHERE TABLE_NAME='" + tableName + "' _ AND COLUMN_NAME='" + columnName + "'"; PreparedStatement psSelectDatatype = connection.prepareStatement(sqlSelectDatatype); ResultSet rsDatatype = psSelectDatatype.executeQuery(); String datatypeName; while (rsDatatype.next()) { datatypeName = rsDatatype.getString("DATA_TYPE"); cdm.put(columnName, datatypeName); } psSelectDatatype.close(); rsDatatype.close(); } psSelectColumn.close(); rsColumn.close(); writeBean(folderName, tableName, cdm); } psSelectTable.close(); rsTable.close(); } catch (SQLException ex) { Logger.getLogger(TableBeanMapping.class.getName()).log(Level.SEVERE, null, ex); } } private static void writeBean(String folderName, String tableName, ColumnDatatypeMapping cdm) { FileWriter fileWriter; BufferedWriter bufferedWriter; StringBuilder fileContent; String className = getConventionalClassName(tableName); SQLJavaDatatypeMapping sqlJavaDatatypeMapping = new SQLJavaDatatypeMapping(); try { fileWriter = new FileWriter(folderName + "\" + className + ".java"); bufferedWriter = new BufferedWriter(fileWriter); fileContent = new StringBuilder(); fileContent.append("/*"); fileContent.append(" * File : ").append(className).append(".java"); fileContent.append(" * Date Created : ").append(Calendar.getInstance().getTime().toString()); fileContent.append(" */"); fileContent.append(" "); fileContent.append("public class ").append(className).append(" {"); fileContent.append(" "); for (ColumnDatatypeEntry entry : cdm.entrySet()) { fileContent.append(" "); fileContent.append("private"); fileContent.append(" "); fileContent.append(sqlJavaDatatypeMapping.getJavaDatatype(entry.getDatatype())); fileContent.append(" "); fileContent.append(entry.getColumn().toLowerCase()); fileContent.append(";"); } for (ColumnDatatypeEntry entry : cdm.entrySet()) { fileContent.append(" "); fileContent.append("public"); fileContent.append(" "); fileContent.append(sqlJavaDatatypeMapping.getJavaDatatype(entry.getDatatype())); fileContent.append(" "); fileContent.append(getAccessorMethodName(entry.getColumn().toLowerCase())); fileContent.append("() {"); fileContent.append(" ").append("return ").append_ (entry.getColumn().toLowerCase()).append(";"); fileContent.append(" ").append("}"); fileContent.append(" "); fileContent.append("public"); fileContent.append(" "); fileContent.append("void"); fileContent.append(" "); fileContent.append(getMutatorMethodName(entry.getColumn().toLowerCase())); fileContent.append("("); fileContent.append(sqlJavaDatatypeMapping.getJavaDatatype(entry.getDatatype())); fileContent.append(" ").append(entry.getColumn().toLowerCase()); fileContent.append(") {"); fileContent.append(" ").append("this.").append_ (entry.getColumn().toLowerCase()).append(" = ").append_ (entry.getColumn().toLowerCase()).append(";"); fileContent.append(" ").append("}"); } fileContent.append(" ").append("}"); bufferedWriter.write(fileContent.toString()); bufferedWriter.close(); } catch (IOException ex) { Logger.getLogger(TableBeanMapping.class.getName()).log(Level.SEVERE, null, ex); } } public static String getConventionalClassName(String str) { String conventionalClassName = ""; String[] splittedStr = str.split("[_]"); for (int i = 0; i
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote