#1
  1. PHP & Java Error Master
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jun 2003
    Location
    My Computer
    Posts
    1,219
    Rep Power
    0

    JDBC & Sybase - Odd errors


    Ok, I have a java program that I wrote, that's set up to connect to a Sybase database & collect a "feed" of data. It then outputs this to a dump file to later be imported into a different database engine.

    There's approximately 80,000 rows to be exported, 31 columns per row.

    It works fine for a little while, then in the code I'll outline below, it blows up. It's a SQLException saying "Invalid column name ''.".
    Unfortunatley, the stack trace doesn't outline what line the error occurs on. It only says "Compiled Code" where the line number would be. This is odd since every other line in the stack trace has line numbers for all the other classes referenced in the exception.

    Here's the try block that the error occurs on. It usually dies about 50k lines in, and continues to error on every row thereafter until I'm finished looping through the resultset.

    (Side note: I have rs.close() commented out because for some odd reason, the program was hanging when it reached that line.)

    Seems I can only have 10k characters, so I'll have to limit the source to the section the errors come from.

    java Code:
    while(rs.next())
    {
    breakEarly = false;
     
    if(breakEarly)
    {
    	if(i > 100)
    	{
    		break;
    	}
    }
     
    if(i % 1000 == 1)
    {
    	System.out.println("Processed " + (i - 1) + " rows.");
    }
     
    try
    {
    	if(rs.getString("approval_status") != null && !(rs.getString("approval_status").equals("")))
    		approval_status = rs.getString("approval_status");
    	else
    		approval_status = "";
     
    	if(rs.getString("approvals_required") != null && !(rs.getString("approvals_required").equals("")))
    		approvals_required = rs.getString("approvals_required");
    	else
    		approvals_required = "";
     
    	if(rs.getString("approved_groups") != null && !(rs.getString("approved_groups").equals("")))
    		approved_groups = rs.getString("approved_groups");
    	else
    		approved_groups = "";
     
    	if(rs.getString("assign_dept") != null && !(rs.getString("assign_dept").equals("")))
    		assign_dept = rs.getString("assign_dept");
    	else
    		assign_dept = "";
     
    	if(rs.getString("category") != null && !(rs.getString("category").equals("")))
    		category = rs.getString("category");
    	else
    		category = "";
     
    	if(rs.getString("close_time") != null && !(rs.getString("close_time").equals("")))
    		close_time = rs.getString("close_time");
    	else
    		close_time = "";
     
    	if(rs.getString("date_entered") != null && !(rs.getString("date_entered").equals("")))
    		date_entered = rs.getString("date_entered");
    	else
    		date_entered = "";
     
    	if(rs.getString("description") != null && !(rs.getString("description").equals("")))
    	{
    		description = rs.getString("description");
    		if(description.length() > 3500)
    		{
    			description = description.substring(0, 3500);
    		}
    	}
    	else
    		description = "";
     
    	if(rs.getString("duration") != null && !(rs.getString("duration").equals("")))
    		duration = rs.getString("duration");
    	else
    		duration = "";
     
    	if(rs.getString("lm_assigned_to_firstname") != null && !(rs.getString("lm_assigned_to_firstname").equals("")))
    	{
    		lm_assigned_to_firstname = rs.getString("lm_assigned_to_firstname");
    		if(lm_assigned_to_firstname.length() > 3500)
    		{
    			lm_assigned_to_firstname = lm_assigned_to_firstname.substring(0, 3500);
    		}
    	}
    	else
    		lm_assigned_to_firstname = "";
     
    	if(rs.getString("lm_assigned_to_lastname") != null && !(rs.getString("lm_assigned_to_lastname").equals("")))
    		lm_assigned_to_lastname = rs.getString("lm_assigned_to_lastname");
    	else
    		lm_assigned_to_lastname = "";
     
    	if(rs.getString("lm_closed_by") != null && !(rs.getString("lm_closed_by").equals("")))
    		lm_closed_by = rs.getString("lm_closed_by");
    	else
    		lm_closed_by = "";
     
    	if(rs.getString("lm_hostname") != null && !(rs.getString("lm_hostname").equals("")))
    		lm_hostname = rs.getString("lm_hostname");
    	else
    		lm_hostname = "";
     
    	if(rs.getString("lm_office_name") != null && !(rs.getString("lm_office_name").equals("")))
    		lm_office_name = rs.getString("lm_office_name");
    	else
    		lm_office_name = "";
     
    	if(rs.getString("lm_outage_duration") != null && !(rs.getString("lm_outage_duration").equals("")))
    		lm_outage_duration = rs.getString("lm_outage_duration");
    	else
    		lm_outage_duration = "";
     
    	if(rs.getString("lm_owner_group") != null && !(rs.getString("lm_owner_group").equals("")))
    		lm_owner_group = rs.getString("lm_owner_group");
    	else
    		lm_owner_group = "";
     
    	if(rs.getString("lm_requested_by_firstname") != null && !(rs.getString("lm_requested_by_firstname").equals("")))
    		lm_requested_by_firstname = rs.getString("lm_requested_by_firstname");
    	else
    		lm_requested_by_firstname = "";
     
    	if(rs.getString("lm_requested_by_lastname") != null && !(rs.getString("lm_requested_by_lastname").equals("")))
    		lm_requested_by_lastname = rs.getString("lm_requested_by_lastname");
    	else
    		lm_requested_by_lastname = "";
     
    	if(rs.getString("lm_type_of_change") != null && !(rs.getString("lm_type_of_change").equals("")))
    		lm_type_of_change = rs.getString("lm_type_of_change");
    	else
    		lm_type_of_change = "";
     
    	if(rs.getString("network_affected") != null && !(rs.getString("network_affected").equals("")))
    		network_affected = rs.getString("network_affected");
    	else
    		network_affected = "";
     
    	if(rs.getString("number") != null && !(rs.getString("number").equals("")))
    		number = rs.getString("number");
    	else
    		number = "";
     
    	if(rs.getString("operator") != null && !(rs.getString("operator").equals("")))
    		operator = rs.getString("operator");
    	else
    		operator = "";
     
    	if(rs.getString("orig_date_entered") != null && !(rs.getString("orig_date_entered").equals("")))
    		orig_date_entered = rs.getString("orig_date_entered");
    	else
    		orig_date_entered = "";
     
    	if(rs.getString("orig_operator") != null && !(rs.getString("orig_operator").equals("")))
    		orig_operator = rs.getString("orig_operator");
    	else
    		orig_operator = "";
     
    	if(rs.getString("planned_end") != null && !(rs.getString("planned_end").equals("")))
    		planned_end = rs.getString("planned_end");
    	else
    		planned_end = "";
     
    	if(rs.getString("prereq_changes") != null && !(rs.getString("prereq_changes").equals("")))
    		prereq_changes = rs.getString("prereq_changes");
    	else
    		prereq_changes = "";
     
    	if(rs.getString("resolved_problems") != null && !(rs.getString("resolved_problems").equals("")))
    		resolved_problems = rs.getString("");
    	else
    		resolved_problems = "";
     
    	if(rs.getString("status") != null && !(rs.getString("status").equals("")))
    		status = rs.getString("status");
    	else
    		status = "";
     
    	if(rs.getString("sysmodtime") != null && !(rs.getString("sysmodtime").equals("")))
    		sysmodtime = rs.getString("sysmodtime");
    	else
    		sysmodtime = "";
     
    	if(rs.getString("system") != null && !(rs.getString("system").equals("")))
    		system = rs.getString("system");
    	else
    		system = "";
     
    	if(rs.getString("total_pages") != null && !(rs.getString("total_pages").equals("")))
    		total_pages = rs.getString("total_pages");
    	else
    		total_pages = "";
    }
    catch(Exception e)
    {
    	e.printStackTrace();
    }
  2. #2
  3. No Profile Picture
    rebel with a cause
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    May 2004
    Location
    The Batsh!t Crazy State.
    Posts
    5,814
    Rep Power
    3466
    Did you check all of your column names against the database to ensure that you had the correct column names? (It's a stupid question I know but sometimes people forget.)
    Dear God. What is it like in your funny little brains? It must be so boring.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Nov 2004
    Location
    Washington DC
    Posts
    2,755
    Rep Power
    1576
    ugh...that's a lot to go through

    The only thing i can think of is maybe you're incosistent on your column names between the if and where you set your vairable inside the if.

    Maybe put in some debugging statements in your if's so you know which one will toss the exception.

    I'm on a conference call, which is code for I'm doing nothing and noticed this....

    Code:
    165. resolved_problems = rs.getString("");
    Can you do something like that?

    Comments on this post

    • crownjewel82 agrees : good catch
    • mrider agrees : [quote]I'm on a conference call, which is code for I'm doing nothing and noticed this....[/quote] LOL
    Last edited by tfecw; February 1st, 2006 at 01:04 PM.
    Open for extension, closed for modification
  6. #4
  7. PHP & Java Error Master
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jun 2003
    Location
    My Computer
    Posts
    1,219
    Rep Power
    0
    Wow, that's embarassing.
    Haha, man I'm blind. That would probably be why it's dying then.
    I'll rerun it and see.

    Thanks!
  8. #5
  9. PHP & Java Error Master
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jun 2003
    Location
    My Computer
    Posts
    1,219
    Rep Power
    0
    Ok, working fine now, thanks...!

    Comments on this post

    • tfecw agrees : Glad you got it working!
  10. #6
  11. <- My daily commute :^)
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Mar 2005
    Location
    Earth. Welcome.
    Posts
    1,500
    Rep Power
    1703
    A possible optimization:

    Code:
    if(rs.getString("approval_status") != null && !(rs.getString("approval_status").equals("")))
    		approval_status = rs.getString("approval_status");
    	else
    		approval_status = "";
    Code:
    approval_status = rs.getString("approval_status") + "";
    Some JDBC drivers have the annoying habit of returning "null" when they should return null. Test this with your system and see if it helps. It'll shorten your code considerably if it does.
    A -> B: Ride.
  12. #7
  13. PHP & Java Error Master
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jun 2003
    Location
    My Computer
    Posts
    1,219
    Rep Power
    0
    Originally Posted by mrider
    A possible optimization:

    Code:
    if(rs.getString("approval_status") != null && !(rs.getString("approval_status").equals("")))
    		approval_status = rs.getString("approval_status");
    	else
    		approval_status = "";
    Code:
    approval_status = rs.getString("approval_status") + "";
    Some JDBC drivers have the annoying habit of returning "null" when they should return null. Test this with your system and see if it helps. It'll shorten your code considerably if it does.
    In theory, that could make things better, but I won't be using that for 2 reasons:

    1. The loop this is in, combined with the fact that concatention can seriously impact performance makes me not want to do this. Perhaps if I used a StringBuffer instead it would work well.

    2. Requirements have changed, and now I need to do additional checking.

IMN logo majestic logo threadwatch logo seochat tools logo