Reverse engineering sql script inserts to java enumerators

Hello.
I'm working on an application that uses a number os tables to store qualifier information about certain entities. A person can, for example, be an "operator" or an "end-user".
These sets of qualifying data are static, an work as enumerators.
I have a SQL script containig a batch of insert statements which I world like to use to generate the corresponding java enumerator.
So, i I have the following lines in my script:
insert into PERSON_CATEGORY values(1, "operator");
insert into PERSON_CATEGORY values(2, "end-user");
a java enumerator file would be generated containing "operator" and "end-user" as the possible enumeration values.
Can anyone point me to a tool providing the mechanisms necessary to do this?
Thanks in advance,
Hugo Oliveira
[email protected]

Actually you can easily do that with SQL:
select 'public enum Category {'
from dual
union all
select '  '||category||decode(rownum, 1, '', ',')
from PERSON_CATEGORY
union all
select '}'
from dualAssuming that there is a column category in the table person_category (btw: you should avoid INSERTS without stating the table columns as seen in the example in your first post).
The result of this query can directly be saved as a Category.java
Using a shell/batch script this can be automated as well.

Similar Messages

  • Reverse engineering SQL (not database)

    Hello,
    Is it planned to provide a tool to reverse engineer SQL statements as Sourceforge's Revj (Reverse Snowflakes Joins) do ?
    This tool generates an ER Diagramm from an SQL Statement without connecting to the database. a demo is available at http://snowflakejoins.com/
    Nb: It works fine with statements comming from SIEBEL or Oracle BI Analytics.
    Regards
    PAscal

    You can Reverse engineering any database that
    you have an ODBC driver installed for (you can set up an ODBC link to access via the ODBC administration utility under Oracle for Windows NT). From the menu choose Generate=> Capture Design of => Server Model. This brings up a tabbed dialouge box with three source settings.Choose the last radio group item - ODBC. There you will find a choice for MS Acess v7.0 (note:type will be set for you automatically).
    Much success.
    null

  • Reverse engineer sql inserts to enumerators

    Hello.
    I'm working on an application that uses a number os tables to store qualifier information about certain entities. A person can, for example, be an "operator" or an "end-user".
    These sets of qualifying data are static, an work as enumerators.
    I have a SQL script containig a batch of insert statements which I world like to use to generate the corresponding java enumerator.
    So, i I have the following lines in my script:
    insert into PERSON_CATEGORY values(1, "operator");
    insert into PERSON_CATEGORY values(2, "end-user");
    a java enumerator file would be generated containing "operator" and "end-user" as the possible enumeration values.
    Can anyone point me to a tool providing the mechanisms necessary to do this?
    Thanks in advance,
    Hugo Oliveira
    [email protected]

    Hello.
    I would like to do this using enums.
    It would be better if the code could be generated directly from the sql script's inserts (in any markup had to be added, it wouldn't be a problem), but if it's only possible to generate it from the database tables that's OK.
    Thanks,
    Hugo Oliveira
    [email protected]

  • Using an SQL Script file to create database in Java? (monkeyDB.sql)

    Hello!
    I am a writing an SQL Script so that I can re-create my database on another server (im using my laptop to test it on first though).
    I'm connecting to mySQL server using JDBC which works fine, but I was wondering
    how can I run an entire script file, say myScript.sql from within a Java class??
    (an SQL Script is simply a file containing the regular SQL commands and expressions that you might enter at an sql command line prompt)
    example of an SQL Scritp: monkeyDB.sql>>
    //#create new db
    CREATE DATABASE sample_db;
    //#set active db
    USE sample_db;
    //#set table paramaters
    CREATE TABLE monkeys
    (name CHAR(20),
      age INT UNSIGNED,
      sex ENUM('M','F')
    //#create standard monkeys
    INSERT INTO monkeys(name,age,sex) VALUES("Sammy",10,"M");
    INSERT INTO monkeys(name,age,sex) VALUES("Muncht",12,"M");
    INSERT INTO monkeys(name,age,sex) VALUES("Jill",8,"F");
    //#get recordset
    SELECT * FROM monkeys WHERE age < 50;Thanks for your help!

    thanks. :-)
    I thought about that too but I didnt want to hard wire it into the code.
    I guess it isnt possible to output the script file using some command from the sql library..?

  • Reverse Engineering of SQL server in ODI

    Hi,
    I created physical and logical architecture for MSSQL in topology manager. Connection and tested and done successfully.
    Now when I connected to Designer and trying to do selective reverse for MSSQL, its giving me below error :
    The Technology or the Driver used does not support Reverse Engineering
    java.sql.SQLException: [Microsoft][ODBC SQL Server Driver]Invalid Descriptor Index
         at sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown Source)
         at sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source)
         at sun.jdbc.odbc.JdbcOdbc.SQLGetDataString(Unknown Source)
         at sun.jdbc.odbc.JdbcOdbcResultSet.getDataString(Unknown Source)
         at sun.jdbc.odbc.JdbcOdbcResultSet.getString(Unknown Source)
         at sun.jdbc.odbc.JdbcOdbcResultSet.getString(Unknown Source)
         at com.sunopsis.dwg.reverse.Reverse.a(Reverse.java)
         at com.sunopsis.dwg.reverse.Reverse.a(Reverse.java)
         at com.sunopsis.graphical.frame.b.ip.a(ip.java)
         at com.sunopsis.graphical.frame.b.ip.a(ip.java)
         at com.sunopsis.graphical.frame.b.hq.b(hq.java)
         at com.sunopsis.graphical.tools.utils.swingworker.v.call(v.java)
         at edu.emory.mathcs.backport.java.util.concurrent.FutureTask.run(FutureTask.java:176)
         at com.sunopsis.graphical.tools.utils.swingworker.l.run(l.java)
         at edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:665)
         at edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:690)
         at java.lang.Thread.run(Unknown Source)
    Please reply and guide me whats missing???

    I have the same problem (The Technology or the Driver used does not support Reverse Engineering).
    I am using ODBC connection because my SQL SERVER DB use only Window Authentication, and by using JDBC driver you can access Ms SQL SERVER DB only using user-id and password.

  • Execute an SQL Script from Java (myScript.sql) ?

    Hello!
    I am a writing an SQL Script so that I can re-create my database on another server (im using my laptop to test it on first though).
    I'm connecting to mySQL server using JDBC which works fine, but I was wondering
    how can I run an entire script file, say myScript.sql from within a Java class??
    (an SQL Script is simply a file containing the regular SQL commands and expressions that you might enter at an sql command line prompt)
    example of an SQL Scritp: myScript.sql>>
    //#create new db
    CREATE DATABASE sample_db;
    //#set active db
    USE sample_db;
    //#set table paramaters
    CREATE TABLE monkeys
    (name CHAR(20),
      age INT UNSIGNED,
      sex ENUM('M','F')
    //#create standard monkeys
    INSERT INTO monkeys(name,age,sex) VALUES("Sammy",10,"M");
    INSERT INTO monkeys(name,age,sex) VALUES("Muncht",12,"M");
    INSERT INTO monkeys(name,age,sex) VALUES("Jill",8,"F");
    //#get recordset
    SELECT * FROM monkeys WHERE age < 50;Thanks for your help!

    The way I understand it is that your mysql.sql script file uses ';' as a delimeter between statements. So now what you can do is that read the whole file and put it inside a string/stringbuffer. Now put this string/stringbuffer to a stringTokenizer with delimeter set as ';'. this way you will recieve your exact statements without scratching your heads as where the statements begin/ends. :-)
    Now once you have your statements than its just a matter of executing them against the database.
    hope this helps.

  • UML modeling by reverse-engineering a JAVA project

    I can't seem to get over a basic hurdle to get started with UML modeling. I open an existing JAVA project. I then start a new project and choose "UML" and "-Platform model by reverse-engineering a JAVA project". Next I give the UML project a name and try to open my existing JAVA project. But the wizard does not show any project!
    Appreciate your help.
    Phil

    UML in JSE8 can reverse engineer all 4 built-in types of Java project defined in IDE. To prove that, I just downloaded apache ant source 1.6.5 from http://ant.apache.org/srcdownload.cgi and successfully reverse engineered it with JSE8.
    If you have a project with existing ant script , it's extremely easy, you absolutely don't need to hand-create a java project from scratch to specify source, library dependency etc. Just follow the wizard "create a Java project with existing ant script" to specify your Java project location, the ant script location, and * don't forget * to specify the source location. Any project without source folder specified is not considered a valid candidate for Reverse Engineer, and you won't see it listed under the project chooser in UML wizard when trying to associate the current UML project with a Java project. Please right click to bring up your source project properties to verify if you have source package folder correctly spelled out.
    It IS a supported feature, do let us know if you still have troubles to RE your project.

  • Reverse engineering to produce .DDL script

    Hi,
    Does anybody know the best way to reverse engineer all the tables in a 9i account in order to replicate the .DDL script which would have been used to create the table definitions in the first place.
    Also, does anybody know of the best way to similarly produce and ER diagram by reverse engineering either the database account, or the .DDL script which I will gain by acheiving the above.
    Thanks in advance
    Mark

    This can help you a lot:
    DBMS_METADATA
    With DBMS_METADATA you can retrieve complete database object definitions (metadata) from the dictionary by specifying:
    The type of object, for example, tables, indexes, or procedures
    Optional selection criteria, such as owner or name
    Parse items (attributes of the returned objects that are to be parsed and returned separately).
    Optional transformations on the output. By default the output is represented in XML, but callers can specify transformations (into SQL DDL, for example), which are implemented by XSLT (Extensible Stylesheet Language Transformation) stylesheets stored in the database or externally.
    DBMS_METADATA provides the following retrieval interfaces:
    For programmatic use: OPEN, SET_FILTER, SET_COUNT, GET_QUERY, SET_PARSE_ITEM, ADD_TRANSFORM, SET_TRANSFORM_PARAM, FETCH_xxx and CLOSE retrieve multiple objects.
    For use in SQL queries and for browsing: GET_XML and GET_DDL return metadata for a single named object. The GET_DEPENDENT_XML, GET_DEPENDENT_DDL, GET_GRANTED_XML, and GET_GRANTED_DDL interfaces return metadata for one or more dependent or granted objects.
    This chapter discusses the following topics:
    Summary of DBMS_METADATA Subprograms
    http://download-west.oracle.com/docs/cd/B10501_01/appdev.920/a96612/d_metada.htm#ARPLS026
    Joel Pèrez
    http://otn.oracle.com/experts

  • Reverse engineering in Java Studio Enterprise 8.1

    I tried to do the reverse engineering in Java Studio Enterprise 8.1.
    The Reverse Engineering process launches which I can tell from the output log,
    but I didn't see any diagram generated. What could be the problem?
    Thanks!

    to see if the relationships are in the model, try to expand the class and interface nodes and they should have something like the following. If these are absent, there might be something in the reverse engineering process that lost the relationships.
    - package1
    - class1
    - Relationships
    - Implementation
    + interface1
    - package2
    - interface1
    - Relationships
    - Implementation
    + class1
    As for sequence diagram, not sure how you created it. If you just cdfs the classes, you should not see any message except for the lifelines that represent the classes. If you select an operation of a class to do cdfs or reverse engineer operation, the sequence diagram will be generated.

  • Inserting sql scripts in Oracle Warehouse Builder 10g

    Dear all,
    Can anyone please tell me if we can use a process flow to insert scripts in OWB 10g..
    If so, how can i do it??
    I am having a problem to insert sql scripts in OWB 10g r2.
    Infact, i have to write a script and insert it in OWB to populate data from a souce table to a target table.
    I have checked the script in sqlplus and it's working correctly (update being done).
    The problem is that how do i insert the script in OWB?? Can i use a process flow other than OMB PLUS??
    Please help me!!!
    Regards,
    Amrish

    Dear all,
    I have inserted the following script in the sqlplus activity in my process flow.
    INSERT INTO BMADW.TARGET_SALGRADE (GRADE, LOSAL, HISAL) SELECT GRADE, LOSAL, HISAL FROM SCOTT.SALGRADE;
    COMMIT;
    EXIT
    When i run the script in sql*plus, it does the insert and the commit part successfully. I have to press 'ENTER' for SQL*PLUS to exit.
    If i have to end the script, is the word 'EXIT' the right command to use??
    My process flow is deploying successfully but when starting it, still no 'INSERT' has been done. It's taking too much time to run (without giving any error).
    Please help me !!!
    Regards,
    Amrish

  • Can we execution  sql script through java ?

    Hi All,
    Can we execute sql script ("name.sql") through java programe.
    I am not talking about reading sql script one by one and excute.
    I just want to send this sql script to oracle console.
    Or any body can give other alternative I have to lot of db operation in less time.
    - Vikas Kumar Sahu

    Kumar,
    not sure whether this is any help, but you can try and use the code below.
    I've knocked it together in about an hour so it's far from production ready (particularly, assumes one-line comments starting with '#' and nothing else - queries are assumed multi-line, but terminated by ';' the following would cause trouble:
    SELECT * FROM table; SELECT *
    FROM another_table;
    and, of course, you can't get to the ResultSet.
    But, hey, it's a start!
    Best,
    Marco.
    (www.infinitebw.com)
    admin (at) infinitebw.com
    package com.ibw.database;
    import java.io.BufferedReader;
    import java.io.File;
    import java.io.FileNotFoundException;
    import java.io.FileReader;
    import java.io.IOException;
    import java.sql.*;
    import com.ibw.exception.DatabaseException;
    public class SqlScript {
         public final static char QUERY_ENDS = ';';
         private File script;
         private Connection conn;
         private Statement stat;
         * @param args
         * @throws SQLException
         public SqlScript(String scriptFileName) throws SQLException {
              script = new File(scriptFileName);
    // this is a 'custom' class, just use instead getConnection() from the
    // DriverManager instead
              conn = ConnectionManager.getConn("test");
              stat = conn.createStatement();
         public static void main(String[] args) {
              try {
                   SqlScript sqlScript = new SqlScript("C:/temp/myscript.sql");
                   sqlScript.loadScript();
                   sqlScript.execute();
              } catch (SQLException e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
              } catch (IOException e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
         protected void loadScript() throws IOException, SQLException {
              BufferedReader reader = new BufferedReader(new FileReader(script));
              String line;
              StringBuffer query = new StringBuffer();
              boolean queryEnds = false;
              while ((line = reader.readLine()) != null) {
                   if (isComment(line))
                        continue;
                   queryEnds = checkStatementEnds(line);
                   query.append(line);
                   if (queryEnds) {
                        stat.addBatch(query.toString());
                        query.setLength(0);
         private boolean isComment(String line) {
              if ((line != null) && (line.length() > 0))
                   return (line.charAt(0) == '#');
              return false;
         public void execute() throws IOException, SQLException {
              stat.executeBatch();
         private boolean checkStatementEnds(String s) {
              return (s.indexOf(QUERY_ENDS) != -1);
    }

  • Developing Reverse Engineering Program -- JAVA to UML what needed

    Hi there,
    I am wondering why people want to develop reverse engineering?? it is useful? but developing the reverse Engineering sound interesting for me.
    Anyway I just intend to figure out how to develop a reverse Engineering program FROM java to UML diagram. Which create Use cases, class and sequence diagram. Is that possible??
    what kinds of Knowledge I need to know in order to develop reverse Engineering. Is there any tutorial that can teach me on how the Reverse Enginneering works?
    Does Reverse Enginneering check words by words in order to develop the program?
    That all...

    Hi,
    You need a parser, like ANTLR, plus a java grammar for that parser (antlr has one). You need a uml model implementation like MDR, EMF or the obsolete NSUML. You need a diagramming library like GEF or JGraph. With those 3 components you could build your own r.e. tool. search google for urls.
    you're interested in the subject so try to read http://citeseer.nj.nec.com/545406.html and related papers.
    you'll need to understand the java language specification (java.sun.com), JSR26 (jcp.org) [a std mapping from java to uml], and the uml metamodel (download the specification from www.omg.org).
    many reverse engineering scenarios are possible, although not all tools have found time to implement them.
    eg. java class -> class diagram
    java method -> sequence diagram
    I don't know of any tutorials. But you could look at the implementation of ArgoUml (argouml.tigris.org) and ask questions on the developer mailing list.
    That should keep you busy for the rest of the year...

  • Exceuting SQL Script through java

    Hi All
    I am making an installer for my application. How do i execute a SQL script through java. Its a sepeate file that has the SQL script for DB creation.
    Regards
    Abhinav

    If you database support ";" to separate sqll, then you can use Statement.execute(sql); to run all SQLscipt once, otherwise you need to load all sqls into Vector, then reun sql step by step. Copy some code for instance:
    public final static Object[] getSQLStatements(String sqlFile) throws java.
    io.IOException {
    java.util.Vector v = new java.util.Vector(1000);
    try {
    java.io.BufferedReader br = new java.io.BufferedReader(new java.io.
    FileReader(sqlFile));
    java.util.Vector batchs = new java.util.Vector(10);
    String temp;
    while ( (temp = br.readLine()) != null) {
    temp = temp.trim();
    if (temp.length() == 0)
    continue;
    switch (temp.charAt(0)) {
    case '*':
    case '"':
    case '\'':
    // System.out.println(temp);
    break; //Ignore any line which begin with the above character
    case '#': //Used to begin a new sql statement
    if (batchs.size() > 0) {
    v.addElement(getSQLStatements(batchs));
    batchs.removeAllElements();
    break;
    case 'S':
    case 's':
    case '?':
    if (batchs.size() > 0) {
    v.addElement(getSQLStatements(batchs));
    batchs.removeAllElements();
    v.addElement(temp);
    break;
    default:
    batchs.addElement(temp);
    break;
    if (batchs.size() > 0) {
    v.addElement(getSQLStatements(batchs));
    batchs.removeAllElements();
    br.close();
    br = null;
    catch (java.io.FileNotFoundException fnfe) {
    v.addElement(sqlFile); //sqlFile is a sql command, not a file Name
    Object[] statements = new Object[v.size()];
    for (int i = 0; i < v.size(); i++)
    statements[i] = v.elementAt(i);
    return statements;
    for (int i = 0; i < statements.length; i++) {
    if (statements[i] instanceof java.lang.String) {
    String temp = (java.lang.String) statements;
    switch (temp.charAt(0)) {
    case 'S':
    case 's':
    case '?':
    System.out.println(temp);
    rs = stmt.executeQuery(temp);
    ResultSetMetaData resultSetMetaData = rs.
    getMetaData();
    int iNumCols = resultSetMetaData.getColumnCount();
    for (int j = 1; j <= iNumCols; j++) {
    System.out.println(resultSetMetaData.getColumnLabel(j)
    + " " + resultSetMetaData.getColumnTypeName(j)
    + " " + resultSetMetaData.getColumnType(j)
    + " " + resultSetMetaData.getPrecision(j)
    + " " + resultSetMetaData.getScale(j)
    Object colval;
    long ncount = 0;
    while (rs.next()) {
    // System.out.print(rs.rowDeleted()+" ");
    ncount++;
    for (int j = 1; j <= iNumCols; j++) {
    colval = rs.getObject(j);
    System.out.print(colval + " ");
    System.out.println();
    rs.close(); //Let the CONCUR_UPDATABLE resultSet release its open files at once.
    rs = null;
    System.out.println(
    "The total row number of resultset: " + ncount);
    System.out.println();
    break;
    default:
    int updateCount = stmt.executeUpdate(temp);
    System.out.println(temp + " : " + updateCount);
    System.out.println();
    else if (statements[i] instanceof java.lang.Object[]) {
    int[] updateCounts;
    Object[] temp = (java.lang.Object[]) statements[i];
    try {
    for (int j = 0; j < temp.length; j++){
    System.out.println( temp[j]);
    stmt.addBatch( (java.lang.String) temp[j]);
    updateCounts = stmt.executeBatch();
    for (int j = 0; j < temp.length; j++)
    System.out.println((j+1)+":"+temp[j]);
    for (int j = 0; j < updateCounts.length; j++)
    System.out.println((j+1)+":" +updateCounts[j]);
    catch (java.sql.BatchUpdateException e) {
    updateCounts = e.getUpdateCounts();
    for (int j = 0; j < updateCounts.length; j++)
    System.out.println((j+1)+":"+updateCounts[j]);
    java.sql.SQLException sqle = e;
    do {
    System.out.println(sqle.getMessage());
    System.out.println("Error Code:" +
    sqle.getErrorCode());
    System.out.println("SQL State:" + sqle.getSQLState());
    sqle.printStackTrace();
    while ( (sqle = sqle.getNextException()) != null);
    catch (java.sql.SQLException sqle) {
    do {
    System.out.println(sqle.getMessage());
    System.out.println("Error Code:" +
    sqle.getErrorCode());
    System.out.println("SQL State:" + sqle.getSQLState());
    sqle.printStackTrace();
    while ( (sqle = sqle.getNextException()) != null);
    stmt.clearBatch();
    System.out.println();

  • Is there any anti reverse engineering or software protection products for JAVA ?

    Hi
    Does anyone knows is there any anti reverse engineering or software protection products for JAVA ?

    By the time this post is written, there is no such tool that comes with the jdk.
    I have used proguard with success applying obfuscation and other features.  

  • Is it Possible to Run SQL Script from Java prog

    Hello
    Is there any API by which we can run SQl Script file ,
    Just by giving database configration parameters and SQL Script file Path ,it will execute that script automatically

    You can excute SQL statemetns throught JDBC, but that doesn't have a facility to read those statements from a file. You'd have to write code to read the file and create and execute statements through JDBC. That should be pretty straightforward though.
    It's conceivable that there's a third party library out there that does it, if you know what to look for.
    If you're not familiar with JDBC, check out http://java.sun.com/developer/onlineTraining/Database/JDBC20Intro/

Maybe you are looking for

  • Regarding the performance in report

    Hi Abap Gurus,                           i am working on the report. my requirement is that after executing the report data gets extracting after 11 hours.the required data is comonf perfectly.  how to improve the performance. any tips to follow the

  • How to change message text encoding in multiple e-mail messages?

    Hello! I'm newcomer in AppleScript. I have imported a lot of email messages from mbox. The problem is that some of messages are displayed in correct russian encoding (KOI8-R) but other messages displayed with incorrect encoding. So i need manually se

  • Cannot log into any GUI modes and need to reinstall OSX

    Hi all, I've been having issues with my iMac 27" i7 desktop which I purchased back in 2011 with OSX Lion. I recently updated to OSX Mavericks and have some issues which I am trying to resolve. I have been working through troubleshooting with the Appl

  • New Macbook Pro 2012 keeps freezing (HELP!!)

    It keeps freezing, it happens after a few hours, sometimes after a few minutes!! First, the app (google chroome, safari, skype)  and then, the finder... I can move the cursor but it doesn't respond, the beach ball won't stop spinning and I had to for

  • 3KEH Balance Sheet Values not updated in Profit Center

    Hello Peofit Center experts I have Assigned Profit Center for few balance Sheet Accounts in 3KEH.But values are not updated in respective Profit Centers. I have to do any configuration settings for transfer Balance Sheet accounts to Profit center or