Marilyn de Queiroz

Sheriff
+ Follow
since Jul 22, 2000
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
12
In last 30 days
0
Total given
0
Likes
Total received
15
Received in last 30 days
0
Total given
5
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Rancher Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Marilyn de Queiroz

Thank you very much for being willing to help me. I did find one more file in Tomcat itself (context.xml) that was separate from the Tomcat context.xml that I could see in Eclipse that contained the wrong IPs. After I updated that file in both places, I am now getting a different (handshake) error. I think that is not related to hibernate and will investigate more on that Friday.

Happy Thanksgiving.

Tim Holloway wrote:Something seems off about that. It sounds like you have a webapp with hard-coded database connection information in it. The only excuse for ever doing that in my book would be if the app is a general-purpose database editor, and definitely not a Hibernate app.


If it were hard-coded into the webapp, I think it would show up in my search. The connections were only found in the xml/properties files. Nothing in the java code or the jsps (this is a really old application originally written in 2002)
As I said, I searched using Eclipse and also in the command line and also using grep (cygwin) and did not find any 10 dot IPs that were not commented out in the xml config files
Hi Tim,

Thanks for the response. I considered excaping the single quotes, but I'm worried. When I insert it into the field, will it also show up as an excaped quote or just as a quote mark? If the escaped quote is stored in the field, I think that the javascript won't work correctly.
Hi,

I'm trying to update a string in a field in DB2. The string contains special characters, but I don't want to modify the string. I've tried updating the string inside a tool (DbVisualizer) and also using a plain SQL update.

The string looks something like this

where I'm trying to add 4 chars to the ReportName to become ReportName_Dev. (This is all one long string. I just broke it up so it would fit on the screen better)

The tool says "There were problems saving to the database table. Review the list, do the necessary changes and try again.
Note: DbVisualizer use bind variables when executing these statements. The effect of this is that the SQL listed below may not be 100% compliant with data formats for the target database i.e. they may fail to execute in for example the SQL Commander."

A straight SQL gives me this message: [Code: -4463, SQL State: 42601]  [jcc][t4][1061][10303][4.22.29] Escape syntax error.  See attached Throwable for details. ERRORCODE=-4463, SQLSTATE=42601

Any ideas on how this can be updated in the table without modifying the string (the href / url) would be appreciated.

Yes!! The HashMap was the culprit. Thank you so much, Junilu. It's working correctly now.  
6 years ago
Thanks, Junilu. I'll try those suggestions.
6 years ago
[quote]What does your code look like? Maybe all you need are fresh pair(s) of eyes to see what's going wrong. [/quote] Hi again, This is obviously a work in progress, but I think you can get the idea. Thanks for taking the time. [code=java]/* import java.io.*; import java.sql.*; import java.text.*; import java.util.*; import java.util.Date; import static java.lang.System.*; public class BillingReportsStagingCounts { private static final Integer ZERO = new Integer("0"); private static String getActiveSchemas = "SELECT ACCOUNT_ID. ACCOUNT_NAME, BOARDED_FLAG, SCHEMA_CD, CLASS " + "FROM table1 AX " + "JOIN table2 CC ON AX.GSMRT_ID = CC.COMPANY_ID " + "JOIN table3 SC ON TBCREATOR = SC.SCHEMA_CD " + "WHERE TBNAME IS NOT NULL"; private static String getCount = "SELECT COUNT(*) \"COUNT\" FROM %schema%.%table% WHERE %date_field% BETWEEN" + " '%lfm_day1%' AND '%lfm_day2%'"; private static String connectionData1 = "jdbc:1.2.3.4:5000/SCHEMA1"; private static String connectionData2 = "jdbc:2.3.4.6:4000/SCHEMA2"; private static String userId1 = "mardeq"; private static String password1 = "XXX"; private static String userId2 = "marilyn"; private static String password2 = "yYY"; private static Timestamp startDttm; private static Timestamp stopDttm; private static Writer writer = null; private static Calendar firstDateOfLFM; private static Timestamp currentTimestamp; // load new driver static { } // get Report Dates static { firstDateOfLFM = Calendar.getInstance(); Calendar lastDateOfLFM = Calendar.getInstance(); startDttm = new Timestamp(firstDateOfLFM.getTimeInMillis()); stopDttm = new Timestamp(lastDateOfLFM.getTimeInMillis()); currentTimestamp = new Timestamp(System.currentTimeMillis()); } // write csv file private static void writeResults(List dataList, String fileName) { System.out.println("Printing"); try { writer = new BufferedWriter(new FileWriter(fileName)); // write headers Map firstRecord = (Map)dataList.get(0); Set headerKeys = firstRecord.keySet(); Iterator iterator = headerKeys.iterator(); while (iterator.hasNext()) { writer.write((String)iterator.next()); writer.write(","); } writer.write("\n"); writer.flush(); // write values for (int i = 0; i < dataList.size(); i++) { Map data = (Map)dataList.get(i); Set keys = data.keySet(); iterator = keys.iterator(); while (iterator.hasNext()) { String key = (String)iterator.next(); String field = (data.get(key).toString()); writer.write(field); writer.write(","); } SimpleDateFormat dfYearMonth = new SimpleDateFormat("yyyy-MM"); SimpleDateFormat dfYearMonthDay = new SimpleDateFormat("yyyy-MM-dd"); String sd = dfYearMonth.format(startDttm); writer.write(sd + ","); String currDt = dfYearMonthDay.format(currentTimestamp); writer.write(currDt); writer.write("\n"); writer.flush(); } } catch (Exception e) { System.out.println("Unable to get file writer"); } } private static ResultSet executeCountSql(Statement statement, String schema, String sql, ResultSet rs) { if (sql.length() > 0) { try { rs = statement.executeQuery(sql); } catch (SQLException e) {} return rs; } private static List getCounts3(List dataList) { List maps = new ArrayList(); Map sbcMap = new TreeMap(); sbcMap.put("ACCOUNT_ID", new Integer(0)); sbcMap.put("ACCOUNT_NAME", "NAME"); sbcMap.put("BOARDED_FLAG", "1"); sbcMap.put("SCHEMA_CD", "SCHEMA2"); sbcMap.put("CLASS", "PRS"); sbcMap.put("COUNT", new Integer(0)); maps.add(sbcMap); sbcMap = new TreeMap(); sbcMap.put("ACCOUNT_ID", new Integer(0)); sbcMap.put("ACCOUNT_NAME", "NAME"); sbcMap.put("BOARDED_FLAG", "1"); sbcMap.put("SCHEMA_CD", "SCHEMA2"); sbcMap.put("CLASS", "WO"); sbcMap.put("COUNT", new Integer(0)); maps.add(sbcMap); String sql7 = ""; Connection connection3 = getConnection(connectionData3, userId3, password3); try { Statement statement = connection3.createStatement(); for (Map data : maps) { String schema = (String)data.get("SCHEMA_CD"); String table = (String)data.get("CLASS"); String sql3 = getCount.replace("%schema%", schema); String sql4 = sql3.replace("%table%", table); String sql5 = sql4.replace("%lfm_day1%", startDttm.toString()); String sql6 = sql5.replace("%lfm_day2%", stopDttm.toString()); sql7 = sql6.replace("%date_field%", "LOAD_DT"); ResultSet rs = statement.executeQuery(sql7); if (rs.next()) { Integer count = rs.getInt(1); if (count != null) { int compare = count.compareTo(ZERO); if (compare == 1) { data.put("COUNT", count); dataList.add(data); } } } rs.close(); } closeStatement(statement); } catch (SQLException e) { e.printStackTrace(); } return dataList; } private static List getCounts(List dataList) { try { Connection con = DriverManager.getConnection(connectionData1, userId1, password1); Statement statement = con.createStatement(); for (Map data : dataList) { String sql7 = ""; ResultSet rs = null; rs = executeCountSql(statement, table, sql7, rs); rs.close(); } } catch (SQLException e) { e.printStackTrace(); } return dataList; } private static List getSchemasAndTables(String sql) { List allTables = new ArrayList(); Connection batchConnection = getConnection(connectionData1, userId1, password1); try { Statement statement = batchConnection.createStatement(); ResultSet rs = statement.executeQuery(sql); ResultSetMetaData metaData = rs.getMetaData(); int columnCount = metaData.getColumnCount(); String[] sourceColumnNames = new String[columnCount + 1]; for (int i = 0; i < columnCount; i++) { sourceColumnNames[i] = metaData.getColumnName(i + 1); } while (rs.next()) { HashMap exbBean = new HashMap(); for (String sourceColumnName : sourceColumnNames) { if (sourceColumnName != null) { Object value = rs.getObject(sourceColumnName); exbBean.put(sourceColumnName, value); } else { exbBean.put("COUNT", 0); } } allTables.add(exbBean); } rs.close(); closeStatement(statement); } catch (SQLException e) { e.printStackTrace(); } return allTables; } private static Connection getConnection(String connectionData, String userId, String password) { Connection connection = null; try { connection = DriverManager.getConnection(connectionData, userId, password); } catch (SQLException e) { e.printStackTrace(); } return connection; } private static void closeStatement(Statement statement) { Connection con = null; try { con = statement.getConnection(); statement.close(); } catch (SQLException e) { e.printStackTrace(); } try { if (con != null) { con.close(); } } catch (SQLException e) { e.printStackTrace(); } } public static void main(String[] args) { List data = new ArrayList(); data = getBatchSchemasAndTables(getActiveSchemas); // for all except SBC & BFS data = getCounts(data); data = getCounts3(data); writeResults(data, "fileName.csv"); } }[/code]
6 years ago
Thanks for the responses, Dave & Junilu (Nice to be back)
The advantage of using maps is that they are flexible. I can read the field name and use it as the "attribute" rather than trying to make the SQL fit into the existing object attributes. If I create a Row class, I have to change the attributes when I change the SQL. Plus I have to add a toString() method to use with the print stuff which means hard-coding the attributes. It seems like I end up with the same decreased flexibility using Rows that I get by hard-coding the code to call each value by key. If I change the SQL, I would have to change the Row, but I don't have to change the Map.
6 years ago
My code is is running multiple SQL queries against different databases (different location, same fields). I put each record of the result into a Map and put the Maps into a List. I want to print the maps to a file.
I add the maps from the second query to the list the same way I add the maps from the first query. I am using TreeMaps because I thought they would sort the keys the same (same key names are in each Map), but it's not working the way I expected.

I iterate through the List to get the Maps, using the first map's keys for the column headers, which works fine for the values in the first database, but the order of the key/value pairs is different between the maps in the list from the first database and the maps in the list from the second database.

So I end up with a column in my file that looks like this
where the first 10 results are from the first database and the last 2 are from a second database.
or this column


I could hard code the keys and use map.get(key), but I was hoping I could do something more dynamic so I can still iterate over the keys but always get them in the same order.
I see in the documentation that the TreeMap uses the "Natural Order", but if the keys are Strings, wouldn't that be alpha order for the Maps in both Lists?
Any suggestions?  
6 years ago
We are in the process of moving code to Git. However, after our development team completes the move, they are thinking of moving other teams (like Requirements team) that use documents. Does it seem that Git would be cumbersome for those types of files? Would it be hard to pull up a previous version of a spreadsheet to compare it (visually) with the current version?

Also, I wonder if having a "non-technical" team setting up ssh to commit their (shared) work will be a drawback.

What is your opinion?
There are different kinds of vegetarians ... including ovo-lacto vegetarians, strict vegetarians
8 years ago
Hi Burt & Kathy,

I'm wondering if this new book covers Java from "beginning to end" or does it concentrate more on the newer stuff? How much emphasis does the exam give to basics vs specific Java version differences ?