?
Solved

Achieiving the equivelent of PHPs mysql_result command in JSP

Posted on 2004-08-10
5
Medium Priority
?
242 Views
Last Modified: 2012-05-05
Hello,

How would I go about getting the same result as PHP's:

$query = mysql_query("SELECT * FROM RUNNINGINSTANCE WHERE UNITLINK = $param");
$instancename1 = mysql_result($query,0,"name");

would in JSP?

Thanks
0
Comment
Question by:ogryn
[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
  • 3
  • 2
5 Comments
 
LVL 35

Accepted Solution

by:
TimYates earned 1000 total points
ID: 11762439
Assuming you have a db connection called "connection", and param is stored in a String variable "param";

-------------------

<%@ page import="java.sql.*" %>
<%
    PreparedStatement stmt =  null ;
    ResultSet rslt = null ;
    try
    {
        PreparedStatement stmt = connection.prepareStatement( "SELECT * FROM RUNNINGINSTANCE WHERE UNITLINK = ?" ) ;
        stmt.setString( 1, param ) ;
        ResultSet rslt = stmt.executeQuery() ;
        if( rslt.next() )
        {
            String instanceName = rslt.getString( "name" ) ;
        }
    }
    catch( SQLException ex )
    {
        out.print( ex.toString() ) ;
    }
    finally
    {
        try { if( rslt != null ) rslt.close() ; } catch( SQLException ex ) {}
        try { if( stmt != null ) stmt.close() ; } catch( SQLException ex ) {}
    }
%>
0
 

Author Comment

by:ogryn
ID: 11762553
Does the 1 in the follwing statement, equate to which row of the database you are reading from?

stmt.setString( 1, param ) ;

0
 
LVL 35

Expert Comment

by:TimYates
ID: 11762618
No, it sets the first ? in the prepares statement :-)

rslt.next() gets the next (first in this case) row of the resultset ready, then you can read the "name" field out of it
0
 

Author Comment

by:ogryn
ID: 11762675
ahh, thanks. I'm a really newbie at Java stuff. I've been using JSTL, but I need to step it up a gear. I'll give that a go. Thanks
0
 
LVL 35

Expert Comment

by:TimYates
ID: 11762815
Hope it works :-)

http://java.sun.com/developer/qow/archive/73/index.html

Should help too :-)

Good Luck!

Tim
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In the absence of a fully-fledged GPO Management product like AGPM, the script in this article will provide you with a simple way to watch the domain (or a select OU) for GPOs changes and automatically take backups when policies are added, removed o…
This month, Experts Exchange’s free Course of the Month is focused on CompTIA IT Fundamentals.
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses

777 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