• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

URGENT! -- Retrieving data from Oracle database?

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello everyone!
I have a problem retrieving data (arabic data)from Oracle database. Bellow is the code for a testing page that should search for a giving name from oracle database and then disply it on the screan.
PS: Even though the input is a correct data, the search returns nothing!
BTW, I'm using apache tomcat installed on windows2000 machine.
ANY HELP WOULD BE GREATLY APPRECIATED!
<%@ page import="java.util.*,java.sql.*,java.lang.* " %>
<%@ page contentType="text/html; charset=Cp1256" %>
<html>
<head>
<title>Map Center</title>"
<meta http-equiv="Content-Type" content="text/html; charset="UTF-8">
</head>
<body class="bgcolour" text="#000000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<table>
<form method='POST' action='arabic_new.jsp'>
<tr>
<td><input type="text" value="" name="arabicvalue"><input type="submit" value="match input"></td>
</tr>
<%
String driver="oracle.jdbc.driver.OracleDriver";
String url="jdbc:oracle:thin:@something001:1521:something";
String username="dubaidata";
String password="dubaidata";
Class.forName(driver).newInstance();
Connection conn=DriverManager.getConnection(url, username, password);
PreparedStatement search = null;
ResultSet rset = null;
ResultSetMetaData metaData = null;
//TEST LANGUAGE SUPPORT
try
{
String alter_language= "ALTER SESSION SET NLS_LANGUAGE = ARABIC";
String alter_territory = "ALTER SESSION SET NLS_TERRITORY ='UNITED ARAB EMIRATES'";
//alter NLS_Language in this session
PreparedStatement ps_alter_language =conn.prepareStatement(alter_language);
ps_alter_language.execute();
ps_alter_language.close();
System.out.println("3");
System.out.println("altered session to read lang - ARABIC");
//alter NLS_TERRITORY in this session
PreparedStatement ps_alter_territory =conn.prepareStatement(alter_territory);
ps_alter_territory.execute();
ps_alter_territory.close();
System.out.println("altered session to read territory - UNITED ARAB EMIRATES");
}
catch (SQLException e)
{
System.out.println("bombed while setting language and territory");
e.printStackTrace();
}
try
{
if(request.getParameter("arabicvalue")==null || request.getParameter("arabicvalue").equals(""))
{
search = conn.prepareStatement("select cname_a from admin where cname_a like '%'");
}
else
{
//out.println("character encoding:"+request.getCharacterEncoding());
out.println("actual input:"+request.getParameter("arabicvalue"));
//THE ABOVE LINE OUTPUT QUESTION MARKS INSTEAD OF THE ACTUAL INPUT!!?
String value=new String(request.getParameter("arabicvalue").getBytes("ISO-8859-1"),"Cp1256");
out.println("<tr>");
out.println("<td>");
out.println("arabic value is:"+value);
out.println("</td>");
out.println("<td>");
out.println("</BR>select cname_a from admin where cname_a like ?");
out.println("</td>");
out.println("</tr>");
search = conn.prepareStatement("select cname_a from admin where cname_a like ?"); //oracle.jsp.util.PublicUtil.setReqCharacterEncoding(value, "ARABIC_UNITED ARAB EMIRATES");
search.setString(1,"%"+value+"%");
}
search.setMaxRows(50);
rset = search.executeQuery();
metaData = rset.getMetaData();
out.println(metaData.getColumnCount());
while (rset.next())
{
//out.println("got a record");
out.println("<tr>");
for (int nCols = 1; nCols <= metaData.getColumnCount(); nCols++)
{
out.println("<td>");
String s=new String(rset.getBytes(nCols),"Cp1256");
out.println(s);
out.println("</td>");
}
out.println("</tr>");
}
search.close();
}
catch (SQLException e)
{
System.out.println("bombed while querying");
e.printStackTrace();
search.close();
}
%>
</form>
</table>
</body>
</html>
 
author
Posts: 621
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"fed",
Thanks for participating here at the Ranch. However, the name you are using does not comply with our naming convention described at http://www.javaranch.com/name.jsp . Please log in with a new name, which meets these requirements.
You can change your name here.
Thanks.
Sean
 
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One thing is that I think the word ARABIC in this line needs to be within single quotes, unless it is.
String alter_language= "ALTER SESSION SET NLS_LANGUAGE = ARABIC";
What kind of output do you get?
 
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First thing you need to check is whether you have connect to the database.
Secondly if it is connected you can use a very simple SQL to select one item to see if it works.
With such approach you will fix your problem.
By the way what the error message you get ?
 
What are your superhero powers? Go ahead and try them on this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic