Connecting to a DB by URL name

Hi all,
I have to retrieve the fields from a database residing on a web server into a buffer by passing a URL name as a parameter.
eg: getting employe names from a employee database on the server. How do i do that.
Thx in advance,
-Suri
[262 byte] By [suri] at [2007-11-15 19:13:44]
# 1 Re: Connecting to a DB by URL name
hai, Jayasudan here.

i think u are not having the JDK 1.1 (or above) documentation.
well i think i can help u giving the exact address (URL) to download the whole bundle of JDK Docs.
www.javasoft.com/products/jdk/1.2/download-docs.html
i think i saw a function in JDBC which takes a URL as a parameter and u have to set 'jdbc' environment
variable for that specifying the protocol and sub-protocol and then the database driver.
i am not sure about the rest of the things. sorry.
as a friend i have given my information.
check out in the documentation.
Jayasudan at 2007-11-10 3:01:39 >
# 2 Re: Connecting to a DB by URL name
Hai suri,
i now have a clear answer to ur question.

before going to the actual programming i would like to tell u some basic
things which u got to do and know about.

to use MS Access, create a database in Access and set it up as an ODBC
data source. to do this,
control panel->ODBC(32 bit)->System DSN tab->Add.. Button->MS Access
Driver->enter appropriate details.

for ex. let us have the DSN as Sample.

Note:
--
by making ur data source a System DSN, it is accessible by more than one
user. thus u can access it by a URL.

to connect to a database using a URL,

Class.forName(driver_string) // this will return the appropriate driver
class for the driver string u are passing. if no driver class is found
for that database, it throws 'ClassNotFoundException'

Connection connection=DriverManager.getConnection(url_string) // this will
connect u to the specified database url string.

Statement statement=connection.createStatement(); // to execute SQL

boolean hasResults=statement.execute(sql_string) // will return true or
false if the SQL has returned value or did not.

ResultSet resultset=statement.getResultSet() // to get the results of the
SQL statement.

that's it.

* give the driver_string's value as sun.jdbc.odbc.JdbcOdbcDriver, because
this is the JDBC driver which comes with the JDK 1.2.
* give the url_string's value as jdbc:odbc:Sample (the DSN).
* sql_string is ur SQL statement.

i think u have downloaded the JDK1.2 docs. if not do it right now, because
it so good and usefull.

hope this info. will be enough and usefull to u.
thank u.
Jayasudan at 2007-11-10 3:02:31 >
# 3 Re: Connecting to a DB by URL name
Oh! thank god, (and you) for that.
just the information i needed.
thanks again.
Justis at 2007-11-10 3:03:32 >
# 4 Re: Connecting to a DB by URL name
dear sir,
i have to important question.

i am pasting the code of a jsp file below... please look in to this...

in this page.. how is he making a database connection... and in this page
where are the select statements and queries... i have tried many times reading
this ..but i could not find the queries ..not even any one.

if anyone sees this jsp file also ... he will not be able to see the queries.
can u please help me .. how to do this type of connection and also how to use queries
like select insert and delete and update .

an example will help me out...please help me...

Ramesh

the file is below...

<%@ include file="jtfincl.jsp" %>

<%@ page language="java" %>
<%@ page import="oracle.apps.ibu.common.IBUContext" %>
<%@ page import="oracle.apps.ibu.common.IbuException" %>
<%@ page import="oracle.apps.ibu.common.Employee" %>
<%@ page import="oracle.apps.ibu.common.EmployeeInfo" %>
<%@ page import="oracle.jdbc.driver.*" %>
<%@ page import="oracle.apps.jtf.aom.transaction.*" %>
<%@ page import="oracle.apps.jtf.base.resources.*" %>
<%@ page import="oracle.apps.jtf.base.interfaces.MessageManagerInter"%>
<%@ page import="oracle.apps.ibu.registration.IbuRegistration" %>
<%@ page import="oracle.apps.ibu.registration.CustomerVO" %>
<%@ page import="oracle.apps.ibu.common.IDNamePair" %>
<%@ page import="oracle.apps.ibu.common.*" %>
<%@ page import="oracle.apps.ibu.registration.*" %>
<%@ page import="java.math.BigDecimal" %>

<jsp:useBean id = "_displayManager"
class = "oracle.apps.ibu.common.DisplayManager"
scope = "application" />

<jsp:useBean id = "ibuPromptManager"
class = "oracle.apps.ibu.common.PromptManager"
scope = "application" />

<%
String appName= "IBU";
boolean stateless=true; // used for jtfsrfp.jsp
SiteProperty.load();
String username = SiteProperty.getGuestUsername();
String password = SiteProperty.getGuestPassword();
%>

<%@ include file="jtfsrfp.jsp" %>

<%
String forwardURL = null;
String backURL = null;
String emailAddress = null;
long employeeID = -1;

String submitType = (String) request.getParameter("submitType");

IBUContext _context = new IBUContext(_fwSession);

String errorKey = "";
String errorMessage = "";
String errorStack = "";

boolean currentStatus = true;

Object lockx = new Object ();
OracleConnection conn = null;
try
{
TransactionScope.begin(lockx);
try
{
conn = (OracleConnection)
TransactionScope.getConnection();
}
catch ( Exception e )
{
throw new FrameworkException("Error getting connection..");
}
if ( conn == null )
{
throw new FrameworkException("Error getting connection..");
}

String<> textMsgs = new String<3>;
MessageManagerInter msgMgr = Architecture.getMessageManagerInstance();
textMsgs<0> = msgMgr.getMessage("IBU_RG_CONTRACT24");
//textMsgs<0> = " is not a valid employee email address.";
textMsgs<1> = msgMgr.getMessage("IBU_RG_CONTRACT25");
//textMsgs<1> = " Cannot get the employee id.";
textMsgs<2> = msgMgr.getMessage("IBU_RG_CONTRACT13");
//textMsgs<2> = "submitType is null, please check program.";

if ( (submitType != null) && "LOGIN".equals( submitType ) )
{
forwardURL="jtflogin.jsp";
backURL="jtflogin.jsp";
}
else if ( (submitType != null) && "EMPLOYEE_CHECK".equals( submitType ) )
{
forwardURL="ibuemplcheck.jsp";
backURL="ibuemplcheck.jsp";
}
else if ( (submitType != null) && "EMPLOYEE_NUMBER_SUBMIT".equals( submitType ) )
{
backURL="ibuemplcheck.jsp";
emailAddress = (String) request.getParameter("emailAddress");
pageContext.setAttribute("emailAddress", emailAddress , PageContext.REQUEST_SCOPE);
employeeID = IbuRegistration.getEmployeeID(conn,emailAddress);
if (employeeID == -1)
{
throw new IbuRegException(emailAddress + " "+textMsgs<0> + " " +textMsgs<1>);
}
//validate employee
currentStatus = Employee.isValidate(conn,emailAddress);
//currentStatus = IbuRegistration.isEmployeeValid(conn,emailAddress);
if (!currentStatus)
{
throw new IbuRegException(emailAddress + " " + textMsgs<0>);
}
/*
EmployeeInfo employee = Employee.findEmployee(conn,employeeID);
pageContext.setAttribute("employee", employee , PageContext.REQUEST_SCOPE);
pageContext.setAttribute("employeeIDStr", Long.toString(employeeID) , PageContext.REQUEST_SCOPE);
*/
forwardURL="ibuemplinput.jsp";
}
else
{ // Cancel button was pressed
throw new IbuRegException(textMsgs<2>);
/* "ibuccsii.jsp"; */
}
}
catch ( IbuException e )
{
TransactionScope.setRollbackOnly();
errorMessage = e.getMessage();
errorStack = IbuRegException.getStack(e);
pageContext.setAttribute("errorMessage", errorMessage , PageContext.REQUEST_SCOPE);
pageContext.setAttribute("errorStack", errorStack , PageContext.REQUEST_SCOPE);
forwardURL = backURL;
}
catch (IbuRegException e)
{
TransactionScope.setRollbackOnly();
errorMessage = e.getMessage();
errorStack = e.getStack();
pageContext.setAttribute("errorMessage", errorMessage , PageContext.REQUEST_SCOPE);
pageContext.setAttribute("errorStack", errorStack , PageContext.REQUEST_SCOPE);
forwardURL = backURL;
}
catch ( Exception e )
{
TransactionScope.setRollbackOnly();
errorMessage = e.getMessage();
errorStack = IbuRegException.getStack(e);
pageContext.setAttribute("errorMessage", errorMessage , PageContext.REQUEST_SCOPE);
pageContext.setAttribute("errorStack", errorStack , PageContext.REQUEST_SCOPE);
forwardURL = backURL;
//throw new FrameworkException( e , "IBU_UNEXPECTED_EXCEPTION");
}
finally
{
TransactionScope.releaseConnection( conn );
TransactionScope.end ( lockx );
}
if (forwardURL == null)
{
forwardURL="jtflogin.jsp";
}

%>
<jsp:forward page= "<%= forwardURL %>" />

<%@ include file="jtferlp.jsp" %>
ramesh123 at 2007-11-10 3:04:38 >
# 5 Re: Connecting to a DB by URL name
hi ramesh123,
i have no knowledge whatsoever on JSP, so i can't help you with that.
i can however tell you that if you follow Jayasudan instructions, you should have a valid connection to your database.
as for the queries, they are simple (or not simple) sql statements, that you need to write yourself.
say you have a table with some data and you want to retrieve all of it, the sql statement would be:
"SELECT * FROM TABLE_NAME";
if you need some more complex statement, type in "sql tutorials" or something similiar in google, and i'm sure you'd find a some good sql tutorials.
i'm not an expert on sql myself, so what i do, is let ms access do all the work for me.
i create a new query, and then look at the sql code that the access generates.
hope this helps, if you need further assistance dont hesitate to reply.
Justis at 2007-11-10 3:05:39 >