/* * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; * version 2.1 of the License. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * */ import java.io.InputStream; import java.sql.Blob; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.ResultSetMetaData; /** * Describe class PrJDBC here. * * * Created: Tue Oct 4 12:00:09 2005 * * @author Luis Fernando Llana Díaz * @version $Id: PrJDBC.java,v 1.3 2006/02/14 13:27:57 luis Exp $ */ public class PrJDBC { public static void main(String [] args) throws Exception{ Class.forName("com.mysql.jdbc.Driver").newInstance(); Connection con = DriverManager.getConnection("jdbc:mysql://localhost/vazmacon?user=luis&password=diez799"); /* This first query runs correctly */ String sql="select vales.fecha,obras.nombre from vales left join obras on vales.obra=obras.id "; PreparedStatement pstmt = con.prepareStatement(sql); ResultSet rs=pstmt.executeQuery(); ResultSetMetaData rsmd = rs.getMetaData(); System.out.println(rsmd.getColumnName(2)+":"+rsmd.getTableName(2)+":"); rs.next(); System.out.println(rs.getString("obras.nombre")); /* This other query does not */ sql="select vales.fecha,obras.nombre from vales left join obras on vales.obra=obras.id order by obras.nombre"; pstmt = con.prepareStatement(sql); rs=pstmt.executeQuery(); rsmd = rs.getMetaData(); System.out.println(rsmd.getColumnName(2)+":"+rsmd.getTableName(2)+":"); rs.next(); System.out.println(rs.getString("obras.nombre")); } }