<?xml version='1.0' encoding="utf-8"?>
      <rss version='2.0'>
      <channel>
      <title>Форум на Исходниках.RU</title>
      <link>https://forum.sources.ru</link>
      <description>Форум на Исходниках.RU</description>
      <generator>Форум на Исходниках.RU</generator>
  	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=412266&amp;view=findpost&amp;p=3763652</guid>
        <pubDate>Tue, 13 Mar 2018 16:00:04 +0000</pubDate>
        <title>Как правильно заносить строковые значения содержащие апостроф в бд mySQL?</title>
        <link>https://forum.sources.ru/index.php?showtopic=412266&amp;view=findpost&amp;p=3763652</link>
        <description><![CDATA[korvin: <div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=412266&view=findpost&p=3763563'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>Astrgan &#064; <time class="tag-quote__quoted-time" datetime="2018-03-13T04:05:44+03:00">13.03.18, 01:05</time></span><div class='quote '>Когда я выполняю SQL-запрос в своем коде на java, через driverManager, то получаю в базе вместо апострофа - &#092;u0027.<br>
</div></div><br>
Видимо, потому что в БД кодировка не Unicode.]]></description>
        <author>korvin</author>
        <category>Java</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=412266&amp;view=findpost&amp;p=3763622</guid>
        <pubDate>Tue, 13 Mar 2018 11:38:39 +0000</pubDate>
        <title>Как правильно заносить строковые значения содержащие апостроф в бд mySQL?</title>
        <link>https://forum.sources.ru/index.php?showtopic=412266&amp;view=findpost&amp;p=3763622</link>
        <description><![CDATA[Астарот: <div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=412266&view=findpost&p=3763563'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>Astrgan &#064; <time class="tag-quote__quoted-time" datetime="2018-03-13T01:05:44+00:00">13.03.18, 01:05</time></span><div class='quote '>в своем коде на java</div></div><br>
<div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=412266&view=findpost&p=3763563'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>Astrgan &#064; <time class="tag-quote__quoted-time" datetime="2018-03-13T01:05:44+00:00">13.03.18, 01:05</time></span><div class='quote '>PreparedStatement statement</div></div><br>
На дворе 2018, работать с сырым jdbc уже не надо, пользуйтесь jdbcTemplate что ли.]]></description>
        <author>Астарот</author>
        <category>Java</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=412266&amp;view=findpost&amp;p=3763619</guid>
        <pubDate>Tue, 13 Mar 2018 11:25:56 +0000</pubDate>
        <title>Как правильно заносить строковые значения содержащие апостроф в бд mySQL?</title>
        <link>https://forum.sources.ru/index.php?showtopic=412266&amp;view=findpost&amp;p=3763619</link>
        <description><![CDATA[VisualProg: <div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=412266&view=findpost&p=3763563'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>Astrgan &#064; <time class="tag-quote__quoted-time" datetime="2018-03-13T01:05:44+00:00">13.03.18, 01:05</time></span><div class='quote '>я выполняю SQL-запрос в своем коде на java</div></div><br>
При таком подходе, вы сами обязаны взять на себя проблему экранирования кавычек, и защиту от инъекций. Либо используйте bind параметры с готовыми библиотеками для работы с SQL скриптами, либо самостоятельно проверяйте содержимое значений ваших параметров на предмет наличия кавычек или инъекций.]]></description>
        <author>VisualProg</author>
        <category>Java</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=412266&amp;view=findpost&amp;p=3763565</guid>
        <pubDate>Tue, 13 Mar 2018 02:42:53 +0000</pubDate>
        <title>Как правильно заносить строковые значения содержащие апостроф в бд mySQL?</title>
        <link>https://forum.sources.ru/index.php?showtopic=412266&amp;view=findpost&amp;p=3763565</link>
        <description><![CDATA[Astrgan: Забыл указать что поле names, имеет тип данных json. И как я узнал, для этого типа данных это нормально.]]></description>
        <author>Astrgan</author>
        <category>Java</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=412266&amp;view=findpost&amp;p=3763563</guid>
        <pubDate>Tue, 13 Mar 2018 01:05:44 +0000</pubDate>
        <title>Как правильно заносить строковые значения содержащие апостроф в бд mySQL?</title>
        <link>https://forum.sources.ru/index.php?showtopic=412266&amp;view=findpost&amp;p=3763563</link>
        <description><![CDATA[Astrgan: Здравствуйте. <br>
Когда я выполняю SQL-запрос в своем коде на java, через driverManager, то получаю в базе вместо апострофа - &#092;u0027.<br>
<br>
<a class='tag-url' href='http://vfl.ru/fotos/48c1d9ee20934787.html' target='_blank'><img class='tag-img' src='http://images.vfl.ru/ii/1520902943/48c1d9ee/20934787_m.png' alt='user posted image'></a><br>
<br>
<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">public class ParserFilms {</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp;ResultSet resultSet;</div><div class="code_line">&nbsp;&nbsp; &nbsp;void listFilms(){</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;File filmsFolder = new File(&quot;/home/alex/Development/films&quot;);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;File[] films = filmsFolder.listFiles();</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;Properties connInfo = new Properties();</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;connInfo.put(&quot;user&quot;, &quot;root&quot;);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;connInfo.put(&quot;password&quot;, &quot;****&quot;);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;connInfo.put(&quot;useUnicode&quot;,&quot;true&quot;); // (1)</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;connInfo.put(&quot;charSet&quot;, &quot;UTF8&quot;); // (2)</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;try (Connection connection = DriverManager.getConnection(&quot;jdbc:mysql://localhost/films?&quot;, connInfo);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PreparedStatement statement = connection.prepareStatement(&quot;INSERT INTO films(name_film, rating, description, poster, path, year_of_release) VALUE (?, ?, ?, ?, ?, ?)&quot;)) {</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;for (File film:films) {</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;String actors = new String(Files.readAllBytes(Paths.get(film.getPath() + &quot;/actors.txt&quot;)));</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;String description = new String(Files.readAllBytes(Paths.get(film.getPath() + &quot;/description.txt&quot;)));</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;String genres = new String(Files.readAllBytes(Paths.get(film.getPath() + &quot;/genres.txt&quot;)));</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;String names = new String(Files.readAllBytes(Paths.get(film.getPath() + &quot;/names.txt&quot;)));</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;String Producer = new String(Files.readAllBytes(Paths.get(film.getPath() + &quot;/Producer.txt&quot;)));</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;String year = new String(Files.readAllBytes(Paths.get(film.getPath() + &quot;/year.txt&quot;)));</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;String[] namesArray = names.split(&quot; / &quot;);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;for (int i = 0; i&#60;namesArray.length; i++) {</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;namesArray[i] = namesArray[i].trim();</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;statement.setString(1, new Gson().toJson(namesArray));</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;statement.setInt(2,5);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;statement.setString(3, description);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;statement.setString(4,film.getPath() + &quot;/poster.jpg&quot;);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;statement.setString(5, film.getPath() + &quot;filmName&quot;);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;statement.setInt(6,Integer.parseInt(year.trim()));</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;statement.executeUpdate();</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}//for</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;}catch (SQLException | IOException e){</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;e.printStackTrace();</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;}</div><div class="code_line">&nbsp;&nbsp; &nbsp;}</div><div class="code_line">}</div></ol></div></div></div></div><script>preloadCodeButtons('1');</script><br>
<br>
Когда я выполняю похожей запрос через Workbench, то все в порядке:<br>
<a class='tag-url' href='http://vfl.ru/fotos/1183750720934786.html' target='_blank'><img class='tag-img' src='http://images.vfl.ru/ii/1520902943/11837507/20934786_m.png' alt='user posted image'></a><br>
<br>
<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">INSERT INTO films(name_film, rating, description, poster, path, year_of_release) VALUE (&quot;world&#39;s dog&quot;, 5, &quot;Привет мир&quot;, &quot;Пока мир&quot;, &quot;world&#39;s dog&quot;, 2017);</div></ol></div></div></div></div>]]></description>
        <author>Astrgan</author>
        <category>Java</category>
      </item>
	
      </channel>
      </rss>
	