Hi,

It works for me. What command line parameters do you use? What is the
expected result, what is the result you got? Please note you did add
'%' in one case but not the other.

Regards,
Thomas


On Thu, Sep 4, 2008 at 10:40 PM, sergey <[EMAIL PROTECTED]> wrote:
> I find out that "LIKE" do not work in preparedStatemnt.
>
> package like;
>
> import java.sql.Connection;
> import java.sql.DriverManager;
> import java.sql.PreparedStatement;
> import java.sql.ResultSet;
> import java.sql.SQLException;
> import java.util.logging.Level;
> import java.util.logging.Logger;
>
> /**
>  *
>  * @author sergey
>  */
> public class Main {
>
>    private String url = "jdbc:h2:~/like";
>    private String DriverName="org.h2.Driver";
>    private Connection conn=null;
>    private PreparedStatement st=null;
>    private String createTable="DROP TABLE IF EXISTS LIKES; create
> table IF NOT EXISTS likes(name varchar(20))";
>    private String[] values=new String[]
> {"sasha","sergey","nick","vasia", "john"};
>    /**
>     * @param args the command line arguments
>     */
>    public static void main(String[] args) {
>        if(args.length==2)
>        {
>            Main m=new Main();
>            m.LikeStatemen(args[0]);
>        }
>        else if(args.length==1){
>            Main m=new Main();
>            m.noLikeStatement(args[0]);
>        }
>        else
>        {
>            System.out.println("Input sign or two");
>        }
>    }
>
>    public Main(){
>        try {
>            Class.forName(DriverName);
>            try {
>                conn = DriverManager.getConnection(url, "sa", "");
>                st=conn.prepareStatement(createTable);
>                st.execute();
>                //////////////////////////////////////////////
>                String sql="insert into likes values(?)";
>                st=conn.prepareStatement(sql);
>                for(int i=0;i<values.length;i++)
>                {
>                    st.setString(1, values[i]);
>                    st.executeUpdate();
>                }
>                st.close();
>            } catch (SQLException ex) {
>
> Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
>            }
>        } catch (ClassNotFoundException ex) {
>            Logger.getLogger(Main.class.getName()).log(Level.SEVERE,
> null, ex);
>        }
>
>    }
>    private void LikeStatemen(String creteria){
>        try {
>                String likeSql="select * from likes where name
> like ?";
>                st=conn.prepareStatement(likeSql);
>                st.setString(1, creteria);
>                ResultSet rs=st.executeQuery();
>                while(rs.next())
>                {
>                    System.out.println(rs.getString(1));
>                }
>
>            } catch (SQLException ex) {
>
> Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
>            }
>
>    }
>
>    private void noLikeStatement(String creteria){
>        try {
>
>                String likeSql="select * from likes where name like
> '"+creteria+"%'";
>                st=conn.prepareStatement(likeSql);
>                ResultSet rs=st.executeQuery();
>                while(rs.next())
>                {
>                    System.out.println(rs.getString(1));
>                }
>
>            } catch (SQLException ex) {
>
> Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
>            }
>
>    }
> }
>
> or, if I'm wrong correct me.
>
> Best regards, Sergey.
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "H2 
Database" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/h2-database?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to