Bug #20780 Can't query for a view
Submitted: 29 Jun 2006 15:52 Modified: 29 Jun 2006 16:51
Reporter: A P Email Updates:
Status: Not a Bug Impact on me:
None 
Category:Connector / J Severity:S1 (Critical)
Version:5.0 OS:Windows (Win/Linux?)
Assigned to: CPU Architecture:Any

[29 Jun 2006 15:52] A P
Description:
Hello,

It appears that I'm unable to query for a view while querying for a table works just fine. Try the code below.

How to repeat:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class testClass {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Connection currentMySQL = null;		
		String mySqlServerName = "xxxxx";
		try {
			Class.forName("com.mysql.jdbc.Driver");
			if (currentMySQL == null || currentMySQL.isClosed()) {
				currentMySQL = DriverManager.getConnection("jdbc:mysql://"
						+ mySqlServerName + "/" + "xxxx" + "?user="
						+ "xxx" + "&password="
						+ "xxxxxx"
						+ "&zeroDateTimeBehavior=convertToNull");
				currentMySQL.setAutoCommit(false);
				currentMySQL.setTransactionIsolation(com.mysql.jdbc.Connection.TRANSACTION_READ_COMMITTED);
				//System.out.println("Connecting to MySQL ("+mySqlServerName+")!", true);
			}
		} catch (Exception e) {
			System.out.println("ERROR: Cannot Open DB Connection to MySQL! Error: " + e.getMessage());
		}
		
		try {
			Statement stmtMySQL = currentMySQL.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, ResultSet.CLOSE_CURSORS_AT_COMMIT);
//	DOESN'T WORK	    ResultSet rs = stmtMySQL.executeQuery("SELECT * FROM view_transfer_msg_files v limit 1;");
/*WORKS*/		    ResultSet rs = stmtMySQL.executeQuery("SELECT * FROM dnis v limit 1;");
		    if (rs.next())
		    {
				System.out.println ("got stuff");
		    }
		    if(rs != null) try {rs.close();}
		    catch(SQLException eSQL) {System.out.println("ERROR: Could not close rs! Error: " + eSQL.getMessage());}
		    if(stmtMySQL != null) try {stmtMySQL.close();}
		    catch(SQLException eSQL) {System.out.println("ERROR: Could not close stmtMySQL! Error: " + eSQL.getMessage());}
		}
	    catch(SQLException eSQL) {System.out.println("ERROR: Could not get mySQL ("+mySqlServerName+") Execution Data Error: " + eSQL.getMessage());}
		
		try {
			if (currentMySQL != null || !currentMySQL.isClosed()) {
				currentMySQL.close();
				//System.out.println("Disconnecting from MySQL ("+mySqlServerName+")", true);
			}
		} catch (Exception e) {
			System.out.println("ERROR: Cannot Close DB Connection to MySQL ("+mySqlServerName+")! Error: " + e.getMessage());
		}
	}

}
[29 Jun 2006 15:57] A P
Btw, the view works fine if you do a select in query browser.
[29 Jun 2006 16:51] A P
User Error.