Results 1 to 3 of 3
  1. #1
    stefanybaez is offline Member
    Join Date
    Nov 2008
    Posts
    4
    Rep Power
    0

    Default Help!! how to turn query result to string

    I have this code


    while (rs.next()) {
    String temp = rs.getString("localizacion_hora");
    String [] temp2 = temp.split("\\-");

    sql2 = "SELECT Asignaturas.nombre FROM Asignaturas , Horario WHERE Horario.codigo_asignatura = Asignaturas.codigo_asignatura AND Horario.localizacion_hora = '"+temp+"'";

    rs2 = stmt.executeQuery(sql2);


    model.insertRow(model.getRowCount(),
    new Object[]{rs.getString("codigo_asignatura"), rs.getString("seccion"),
    temp2[0], temp2[3], temp2[1], temp2[2], rs.getString("codigo_profesor")});

    }

    In red is a query that returns one value, a class name, how can i store that in a string ??


    I tried this:
    String temp = rs.getString("Asignaturas.nombre");
    but didnt work =S
    someone told me i should call resultset's next, but i tried that too and it didn't work, maybe im not doing it right (im obviously not doing it right =P)

    Any help would be greatly appreciated!

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    You need to use a new statement object (not the same one as for the first query) to set off the second query (and I assume you mean rs2.getString, rather than rs.getString). And yes an rs.next or rs.first is needed.
    Last edited by masijade; 12-04-2008 at 08:13 PM.

  3. #3
    archanab is offline Member
    Join Date
    Dec 2008
    Posts
    3
    Rep Power
    0

    Default

    Stefany, not sure if you have got the solution if not then apart from what masijade mentioned could you modify
    String temp = rs.getString("Asignaturas.nombre");
    to
    String temp = rs.getString("nombre");

    Possible error there is invalid column name. You can keep alias in the query statement but not in the rs.getString() method.

Similar Threads

  1. Java Popup Window & Url Query String Value
    By Rivelyn in forum New To Java
    Replies: 4
    Last Post: 01-20-2011, 06:03 AM
  2. Replies: 1
    Last Post: 08-22-2008, 07:28 PM
  3. Raising alerts based on query result across the network
    By srinivasan.sr in forum Networking
    Replies: 2
    Last Post: 07-22-2008, 07:47 AM
  4. [SOLVED] General string problem in my database query.....?
    By prabhurangan in forum New To Java
    Replies: 7
    Last Post: 06-25-2008, 09:55 AM
  5. Export query result, procces is to slow
    By Daniel in forum Enterprise JavaBeans (EJB)
    Replies: 2
    Last Post: 06-28-2007, 07:35 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •