Solved

JSP for mySQL to Oracle

Posted on 2003-11-24
7
384 Views
Last Modified: 2010-04-01
I have a small program that is written using JSP using mySQL at the backend (development) and I am thinking to move it to Oracle (production). There are a few conversion issues and I appreciate your input and suggestions:

1. In mySQL there is auto_increment function but not in Oracle 9i. In my JSP sql (that uses mySQL) I could have just use

insert into t_emp (id, name) value ('', 'Joe Black');

In oracle I uses sequence and the sql looks like:

insert into t_emp values (emp_seq.nextval, 'Joe Black');

How could I use just 1 type of sql for both databases?

2. If I use NOW() in the DATETIME in mySQL in some INSERT statement, what should I replace with in Oracle? sysdate seems to be doing the equivalent.

My real questions is, using JSP, how could I program in such a way that my program is independent of the database at the backend?

Thank you.
0
Comment
Question by:Tuan_Jean
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 6

Accepted Solution

by:
jarasa earned 40 total points
ID: 9816699
Hi Tuan_Jean.

I guess is not a way that you could do that, unless that you uses the DB as a parameter and put it on the the code. Different DBs uses different sentences or functions so you have to take care of them. is like the AS on the FROM statement you can't use it in Oracle but you must use it in mySQL.

If you have a way to Know the DB uses just make a switch on the code and send the proper statement to the DB.

regards

Javier
0
 

Author Comment

by:Tuan_Jean
ID: 9820993
Thank you.
0
 
LVL 6

Expert Comment

by:jarasa
ID: 9823162
Hi Tuan_Jean.
Did you solve the problem as I recomended you?
If you did I wonder why you assigned me a C grade instead an A grade.
regards
Javier.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Tuan_Jean
ID: 9828184
Javier,

I understand the method you recommended are working but didn't use it as this makes the code very complex as each sql statement will have to had a switch.

However, I am not sure how the Grade C comes into the picture. I am happy to assign grade A. How do I do it?
0
 
LVL 6

Expert Comment

by:jarasa
ID: 9830715
HI Tuan_Jean.

Actually there is a way that you could do it without a switch, if you place a session variable with the DB used onces you start the application you could have a constants file with all your querys for the different DataBase and use them as needed compounding them at runtime on the JSP, somethin like this.

constants.java
public class Constants
{

    public Constants()
    {
    }

    public static final String [] ORACLE = {"ORACLE SQL 1","ORACLE SQL 2"};
    public static final String [] mySQL = {"mySQL SQL 1","mySQL SQL 2"};
   
    public String get(String s, int n) {
          String p;
             // You can make a switch here if you have more than 2 DBs
          if(s.equals("ORACLE"))
                p = this.ORACLE[n];
          else
                p = this.mySQL[n];
          return p;
          
    }
}

access.jsp
<%@ page import="Constants" %>
<%
session.putValue("DB", "ORACLE"); // Obviously you must put this in the login jsp
Constants c = new Constants();
String sql = c.get((String) session.getAttribute("DB"),0);
......
%>
<html>
<head>
<title>Documento sin t&iacute;tulo</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<%=sql%>
</body>
</html>


About the A grade I thisk you shoud just post a comment to the sdministrators saying that you want the Grade changed for this question from C to A.

regards.
Javier
0
 

Author Comment

by:Tuan_Jean
ID: 9833844
Javier. Thank you again.
0
 

Author Comment

by:Tuan_Jean
ID: 9833850
Dear Administrator, I am very please with the answer Javier posted. Could you please change the grade from C to A. Thank you.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

CTAs encourage people to do something specific to show interest in your company, product or service. Keep reading to learn why CTAs should always be thought of as extremely important, albeit small, sections of websites.
How many times a day do you open, acknowledge, or close an IT incident? What’s your process? Do you have a process depending on the incident, systems involved, and other factors? New Relic Alerts gives you options for how you interact with notifica…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
Suggested Courses

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question