Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8311093
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T19:41:53+00:00 2026-06-08T19:41:53+00:00

I cannot select a backslash from a table if I use the like keyword.

  • 0

I cannot select a backslash from a table if I use the “like” keyword.
it’s working fine with the derby database, so I want to ask is the sql incorrect? or the backslash has special meaning in h2?
Thank you:)

public class HelloWorld {
public static void main(String... args) throws Exception {
    // delete the database named 'test' in the user home directory
    DeleteDbFiles.execute("~", "test", true);
    Class.forName("org.h2.Driver");
    Connection conn = DriverManager.getConnection("jdbc:h2:~/test");
    Statement stat = conn.createStatement();
    stat.execute("create table test(" +
            "id int primary key, " +
            "name varchar(255))");
    try {
        int id = 1;
        String name = "\\";
        stat.execute("insert into test values("+id+",'"+name+"')");
        ResultSet rs = stat.executeQuery("select * from test");
        while(rs.next()) {
            System.out.println(rs.getString(1)+" "+rs.getString(2));
        }
        ResultSet rs2 = stat.executeQuery(
              "select * from test where name like '"+name+"%'");
        // ResultSet rs2 = stat.executeQuery(
              "select * from test where name = '"+name+"'");
        while(rs2.next()) {
            System.out.println(rs2.getString(1)+" "+rs2.getString(2));
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    stat.close();
    conn.close();
}
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T19:41:54+00:00Added an answer on June 8, 2026 at 7:41 pm

    The backslash is the default escape character for LIKE conditions.

    I guess you need to use two backslashes, that is, within Java, you need to write "\\\\". Or, as an alternative, use LIKE '\' ESCAPE '' (to use no escape character).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got: mysql_connect($host,$username,$password); @mysql_select_db(db) or die(Error: Cannot select database); $query = select password from
I am trying to use GroupLayout from NetBeans 7.0, but I simply cannot select
ORA-01445: cannot select ROWID from, or sample, a join view without a key-preserved table
I am facing a problem where-in I cannot select videos from the photo album
I cannot understand this query? select @:vfOutBalance+@:vfHSSubTotal+@3+orpartpayment,@:vfOutBalance+@:vfHSSubTotal from or_equip_upgrd_id what does @3 mean?
I want to change server location but I can't it's greyed (I cannot select
i know how to delete records for jqgrid, but i realise i cannot select
I'm trying the following and cannot find out what is wrong: IF( IFNULL( SELECT
Cannot dump Stack Overflow XML file into SQL Server 2008. Could you please explain
I have the following form code but I cannot select the sell radio in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.