Sorry, I guess I answered too quickly. You have a problem, if you have to use a literal SQL statement, and the various DBMS's use different escape syntax.
However, in Java, you can just use a prepared statement String sql = "INSERT INTO files (filepath) VALUES (?)"); PreparedStatement ps = con.prepareStatement(sql); ps.setString(1, "c:\\Repository\\Pack\\"); ps.executeUpdate(); Hope that works for you. > Subject: RE: About escape character '\' > Date: Thu, 11 Apr 2002 13:54:46 -0400 > From: "Kathy Sung" <[EMAIL PROTECTED]> > To: <[EMAIL PROTECTED]> > > sorry, I should say add 3 extra '\' and not just one in my previous > email, since if I add 3 more and it becomes: > "INSERT INTO files (filepath) VALUES ('c:\\\\Repository\\\\Pack\\\\')" > which represents the following string in Java: > "INSERT INTO files (filepath) VALUES ('c:\\Repository\\Pack\\')" > (because in Java '\' is also an escape character) > > So, in MySQL 'c:\Repository\Pack\' will be inserted, while in MS SQL and > Oracle 'c:\\Repository\\Pack\\' will be inserted and that's the problem > for me... > > -----Original Message----- > From: Bill Easton [mailto:[EMAIL PROTECTED]] > Sent: Thursday, April 11, 2002 7:27 AM > To: [EMAIL PROTECTED] > Cc: Kathy Sung > Subject: Re: About escape character '\' > > > Kathy, > > You shouldn't have a problem here--it's Java, not MySQL, that requires > the > doubled '\' in a string literal. > > In Java, the string literal: > "INSERT INTO files (filepath) VALUES ('c:\\Repository\\Pack\\' )" > represents the string whose content is > INSERT INTO files (filepath) VALUES ('c:\Repository\Pack\' ) > so what gets inserted is, in fact, > c:\Repository\Pack\ > > > Subject: About escape character '\' > > Date: Wed, 10 Apr 2002 19:44:21 -0400 > > From: "Kathy Sung" <[EMAIL PROTECTED]> > > To: <[EMAIL PROTECTED]> > > > > Hi all, > > > > I want to insert the string 'c:\Repository\Pack\' into a mysql table > > using java and I did it as follows: > > > > sql =3D3D "INSERT INTO files (filepath) VALUES ('c:\Repository\Pack\' > )"; > > insertStmt.execute(sql); > > > > I got an error and I know I should add an extra '\' to escape each of > > the '\' in the above sql statement. But, the problem is MS SQL and > > Oracle do not treat '\' as an escape character in sql statements, and > I > > want to keep my Java program as database-independent as possible. (and > I > > don't want the whole string 'c:\\Repository\\Pack\\' to be stored in > the > > database when I use MS SQL server or Oracle) > > > > Any suggestion to my problem will be greatly appreciated. > > > > Thanks, > > Kathy > > > --------------------------------------------------------------------- Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail <[EMAIL PROTECTED]> To unsubscribe, e-mail <[EMAIL PROTECTED]> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php