Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

[impala]Cloudera_ImpalaJDBC4_2.5.5.1007 don't support "prepareStatement"

[impala]Cloudera_ImpalaJDBC4_2.5.5.1007 don't support "prepareStatement"

Explorer
@Test
	public void testPrparedStatement(){
		Connection con = null;
		PreparedStatement stmt = null;
		ResultSet rs = null;

		String sql = "SELECT * FROM default.test where a=?";

		try {
			Class.forName(JDBC_DRIVER);
			con = DriverManager.getConnection(CONNECTION_URL);
			stmt = con.prepareStatement(sql);
			stmt.setNString(1, "apple,101,5.0");
			rs = stmt.executeQuery();

			System.out.printf("%20s%20s\r\n", "A", "B");

			while (rs.next()) {
				// Retrieve values from the row where the
				// cursor is currently positioned using column
				// names
				String a = rs.getString("a");
				String b = rs.getString("b");
				// Display values in columns 20 characters
				// wide in the Console View using the
				// Formatter
				System.out.printf("%20s%20s\r\n", a,b);
			}

		} catch (ClassNotFoundException e) {

			e.printStackTrace();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			try {
				if (rs != null) {
					rs.close();
				}
			} catch (SQLException se1) {

			}
			try {
				if (stmt != null) {
					stmt.close();
				}
			} catch (SQLException se2) {
				// Log this
			}
			try {
				if (con != null) {
					con.close();
				}
			} catch (SQLException se3) {
				// Log this
				se3.printStackTrace();
			}
		}

	}

 

 

could not match input), Query: SELECT * FROM default.test where a=?.

 

1 REPLY 1

Re: [impala]Cloudera_ImpalaJDBC4_2.5.5.1007 don't support "prepareStatement"

Contributor

Hi Kelson,

 

Please use stmt.setString method instead of stmt.setNString method to set the parameter in PreparedStatement. That should work.

 

Don't have an account?
Coming from Hortonworks? Activate your account here