Shawnmax77
Shawnmax77

Reputation: 3

How to change SQL script within Java .class file

A coworker wrote a web piece in Java but he is no longer with us. I am not familiar with Java, but table names in our Application database, which are referenced in SQL scripts within the .class files, need to be updated to reflect software changes. I downloaded Java Decompiler so I can read the code, but I cannot save changes with this program. Is there anything I can do without learning Java?

Upvotes: 0

Views: 473

Answers (3)

Jenya G
Jenya G

Reputation: 514

You have not told us what database you are using and is the only SQL TABLE names that needs to be changed to different name. If you only need to change table names, you can create a VIEW in mysql/oracle/sqlserver/postgresql/db2 that will be like an alias for the old table name. For example mysql:

CREATE VIEW table_name_in_java_class_file AS
SELECT * FROM your_updated_table_name

Since you decompiled class, you can see what table names it references and create a view named like that to point to your new table. But columns need to be the same, in your new table, unless you know for that that class doesn't care about the column types/order/etc. Most likely you will be better off with hiring someone part time to do this for you if you not familiar with Java or programming in general.

Upvotes: 0

Kvk
Kvk

Reputation: 530

There is no way, you can update the content in .class file directly.

  1. save the decompiled code as .java file
  2. change your SQL scripts in that
  3. compile it again .. you will get the .class file with updated changes.
  4. replace the old class file with this one.

Upvotes: 1

Jared
Jared

Reputation: 1897

Without the source you're going to be hurting. You could try using a java decompiler and seeing if you can extract the source and recompile it, but it is not going to be an easy task unless it's trivial java code. Unless you're just digging to see what it does, I'd get the code recompiling before I made any changes to it (since getting it recompiling is going to be the hard part).

FYI, all of this assumes the code is licenses in such a way that decompiling it is OK. Don't send me your lawyer bill if you're breaking a EULA (tongue in cheek, I doubt you'd actually get sued).

Upvotes: 0

Related Questions