Explore Courses Blog Tutorials Interview Questions
0 votes
in SQL by (6.1k points)

What I need to accomplish, is to be able to write the SQL statements and verify the results. The SQL Statements would have the variables in them, like :

String sql = "Select  zoneid from zone where zonename = myZoneName";

Where myZoneName is created from count +

Note: I am using Apache POI to parse Excel Spreadsheet.

here is the code:

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.PreparedStatement;

import java.sql.ResultSet;

import java.sql.SQLException;

import java.util.Properties;

import org.apache.log4j.Logger;

import org.junit.Test;

public class VerifyDBSingleDomain {

    static Logger log = Logger.getLogger(VerifyDBSingleDomain.class.getName());

    String url = "jdbc:oracle:thin:@a.b.c.d:1521:mname";


    public void VerifyDBSingleDomainTest() throws SQLException {

        Properties props = new Properties();

        props.setProperty("user", "user");

        props.setProperty("password", "password");

        String sql = "Select  zoneid from zone where zonename =";

        //String sql = "Select * from zone";

        Connection conn;

        //try {

            conn = DriverManager.getConnection(url, props);

            PreparedStatement preStatement = conn.prepareStatement(sql);

            ResultSet result = preStatement.executeQuery();


            /*while ( {



        } catch (SQLException e) {



    //  }




I am getting the below error:

java.sql.SQLException: ORA-00933: SQL command not properly ended

1 Answer

0 votes
by (12.7k points)

You have to use single quotes in your WHERE clause assuming myZoneName is a text type:

String sql = "Select zoneid from zone where zonename = ''";

To display the zoneid assuming it is an INTEGER type Use the following:

while ( { 



Want to learn more concepts related to SQL? Join SQL Training fast!

Related questions

Browse Categories