<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Der Blog von Benny Neugebauer &#187; MySQL</title>
	<atom:link href="http://www.bennyn.de/tag/mysql/feed" rel="self" type="application/rss+xml" />
	<link>http://www.bennyn.de</link>
	<description>Alles über die Informatik &#38; Co.</description>
	<lastBuildDate>Mon, 06 Feb 2012 11:49:34 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Datenbank-Zugriff mit PHP und PDO</title>
		<link>http://www.bennyn.de/programmierung/php/datenbank-zugriff-mit-php-und-pdo.html</link>
		<comments>http://www.bennyn.de/programmierung/php/datenbank-zugriff-mit-php-und-pdo.html#comments</comments>
		<pubDate>Thu, 12 May 2011 19:33:07 +0000</pubDate>
		<dc:creator>bennyn</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Abfrage]]></category>
		<category><![CDATA[Datenbanken]]></category>
		<category><![CDATA[Eintrag]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PDO]]></category>

		<guid isPermaLink="false">http://www.bennyn.de/?p=2529</guid>
		<description><![CDATA[Beim Zugriff auf eine Datenbank sollte man mit PHP immer auf PDO (PHP Data Objects) zurückgreifen. Durch diese Abstraktionsstufe ist das Datenbank-System später einfacher austauschbar und Prepared Statements lassen sich auch ganz leicht realisieren. Hierzu ein exemplarischer Beispielcode. Code: database.sql 1 2 3 4 5 6 7 8 9 10 11 12 13 DROP DATABASE [...]]]></description>
			<content:encoded><![CDATA[<p>Beim <strong>Zugriff auf eine Datenbank</strong> sollte man mit PHP immer auf <strong>PDO</strong> (PHP Data Objects) zurückgreifen. Durch diese Abstraktionsstufe ist das Datenbank-System später einfacher austauschbar und Prepared Statements lassen sich auch ganz leicht realisieren. Hierzu ein exemplarischer Beispielcode.<br />
<span id="more-2529"></span></p>
<h2>Code:</h2>
<p><b>database.sql</b></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">DROP</span> <span style="color: #993333; font-weight: bold;">DATABASE</span> <span style="color: #993333; font-weight: bold;">IF</span> <span style="color: #993333; font-weight: bold;">EXISTS</span> <span style="color: #ff0000;">`dailydjango`</span>;
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">DATABASE</span> <span style="color: #ff0000;">`dailydjango`</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #993333; font-weight: bold;">CHARACTER</span> <span style="color: #993333; font-weight: bold;">SET</span> utf8 <span style="color: #993333; font-weight: bold;">COLLATE</span> utf8_general_ci;
<span style="color: #993333; font-weight: bold;">USE</span> <span style="color: #ff0000;">`dailydjango`</span>;
&nbsp;
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #993333; font-weight: bold;">IF</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">EXISTS</span> <span style="color: #ff0000;">`feed_entries`</span> 
<span style="color: #66cc66;">&#40;</span>
	<span style="color: #ff0000;">`id`</span>		<span style="color: #993333; font-weight: bold;">INT</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">10</span><span style="color: #66cc66;">&#41;</span>	<span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #993333; font-weight: bold;">AUTO_INCREMENT</span>
	<span style="color: #66cc66;">,</span><span style="color: #ff0000;">`pubdate`</span>	DATETIME <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span>	
	<span style="color: #66cc66;">,</span><span style="color: #ff0000;">`title`</span>	<span style="color: #993333; font-weight: bold;">VARCHAR</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span>
	<span style="color: #66cc66;">,</span><span style="color: #ff0000;">`link`</span>		<span style="color: #993333; font-weight: bold;">VARCHAR</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span>
	<span style="color: #66cc66;">,</span><span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">`id`</span><span style="color: #66cc66;">&#41;</span>
	<span style="color: #66cc66;">,</span><span style="color: #993333; font-weight: bold;">UNIQUE</span> <span style="color: #993333; font-weight: bold;">KEY</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">`link`</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#41;</span> ENGINE <span style="color: #66cc66;">=</span> InnoDB <span style="color: #993333; font-weight: bold;">CHARACTER</span> <span style="color: #993333; font-weight: bold;">SET</span> utf8 <span style="color: #993333; font-weight: bold;">COLLATE</span> utf8_general_ci;</pre></td></tr></table></div>

<p><b>code.php</b></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$HOST</span>	<span style="color: #339933;">=</span> <span style="color: #0000ff;">'localhost'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$DB</span>	<span style="color: #339933;">=</span> <span style="color: #0000ff;">'dailydjango'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$USER</span>	<span style="color: #339933;">=</span> <span style="color: #0000ff;">'root'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$PASS</span>	<span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$TABLE</span>	<span style="color: #339933;">=</span> <span style="color: #0000ff;">'feed_entries'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Test-Daten</span>
<span style="color: #000088;">$test_pubdate</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'2011-05-01 21:30:45'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$test_title</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Ein Titel'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$test_link</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://www.bennyn.de/'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// MySQL-Eintrag</span>
	try 
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$con</span>	<span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> PDO<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;mysql:host=<span style="color: #006699; font-weight: bold;">$HOST</span>;dbname=<span style="color: #006699; font-weight: bold;">$DB</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$USER</span><span style="color: #339933;">,</span> <span style="color: #000088;">$PASS</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$sql</span>	<span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;INSERT INTO <span style="color: #006699; font-weight: bold;">$TABLE</span>(id,pubdate,title,link) VALUES(NULL,:pubdate,:title,:link)&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$stmt</span>	<span style="color: #339933;">=</span> <span style="color: #000088;">$con</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">prepare</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$stmt</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">bindParam</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">':pubdate'</span><span style="color: #339933;">,</span><span style="color: #000088;">$test_pubdate</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$stmt</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">bindParam</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">':title'</span><span style="color: #339933;">,</span><span style="color: #000088;">$test_title</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$stmt</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">bindParam</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">':link'</span><span style="color: #339933;">,</span><span style="color: #000088;">$test_link</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$stmt</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">execute</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$stmt</span>	<span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$con</span>	<span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	catch<span style="color: #009900;">&#40;</span>PDOException <span style="color: #000088;">$ex</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$ex</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getMessage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// MySQL-Abfrage</span>
	try 
	<span style="color: #009900;">&#123;</span>  		
		<span style="color: #000088;">$con</span>	<span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> PDO<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;mysql:host=<span style="color: #006699; font-weight: bold;">$HOST</span>;dbname=<span style="color: #006699; font-weight: bold;">$DB</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$USER</span><span style="color: #339933;">,</span> <span style="color: #000088;">$PASS</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$sql</span>	<span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;SELECT * FROM <span style="color: #006699; font-weight: bold;">$TABLE</span>&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$con</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$record</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">print</span> <span style="color: #000088;">$record</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'id'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">' '</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">print</span> <span style="color: #000088;">$record</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'pubdate'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">' '</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">print</span> <span style="color: #000088;">$record</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'title'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">' '</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">print</span> <span style="color: #000088;">$record</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'link'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000088;">$con</span>	<span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>  
	catch<span style="color: #009900;">&#40;</span>PDOException <span style="color: #000088;">$ex</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$ex</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getMessage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p><u>Hinweis:</u> Die Datenbank-Verbindung sollte nicht immer bei jeder Datenbank-Anfrage neu aufgebaut und abgebaut werden.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bennyn.de/programmierung/php/datenbank-zugriff-mit-php-und-pdo.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL für Python und Django unter Windows</title>
		<link>http://www.bennyn.de/programmierung/python/mysql-fur-python-und-django-unter-windows.html</link>
		<comments>http://www.bennyn.de/programmierung/python/mysql-fur-python-und-django-unter-windows.html#comments</comments>
		<pubDate>Tue, 19 Apr 2011 20:46:15 +0000</pubDate>
		<dc:creator>bennyn</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[Datenbanken]]></category>
		<category><![CDATA[Django]]></category>
		<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://www.bennyn.de/?p=2460</guid>
		<description><![CDATA[Ich lerne gerade die Programmiersprache Python, um das Webframework Django benutzen zu können. Als Windows-Liebhaber habe ich mich sehr gefreut, dass es mit Instant Django eine Lösung gibt, um ganz einfach und unkompliziert entwickeln zu können. Leider ist in &#8220;Instant Django&#8221; keine Schnittstelle für MySQL-Datenbanken enthalten (sondern nur SQLite), weshalb man die MySQL-Unterstützung nachträglich installieren [...]]]></description>
			<content:encoded><![CDATA[<p>Ich lerne gerade die Programmiersprache <strong>Python</strong>, um das <a href="http://www.djangoproject.com/">Webframework Django</a> benutzen zu können. Als Windows-Liebhaber habe ich mich sehr gefreut, dass es mit <a href="http://www.instantdjango.com/"><strong>Instant Django</strong></a> eine Lösung gibt, um ganz einfach und unkompliziert entwickeln zu können. </p>
<p>Leider ist in &#8220;Instant Django&#8221; keine Schnittstelle für <strong>MySQL-Datenbanken</strong> enthalten (sondern nur SQLite), weshalb man die MySQL-Unterstützung nachträglich installieren muss. Wie das geht, zeige ich.<br />
<span id="more-2460"></span></p>
<h2>Einrichtung:</h2>
<p>Meine Annahme ist, dass das Instant Django-Paket bereits entpackt wurde und sich im Ordner &#8220;C:\Users\bennyn\Desktop\Instant Django\django&#8221; befindet. Falls ein anderer Pfad verwendet wird, muss dieser angepasst werden. In Instant Django ist bereits Python in der aktuellen Version 2.7.1 enthalten. Man muss der Windows-Registrierung aber noch sagen, wo sich diese Python-Version befindet. Dazu erstellt man eine Datei namens <b>python.reg</b> mit folgendem Inhalt (Vorsicht! Pfade anpassen!):</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
</pre></td><td class="code"><pre class="ini" style="font-family:monospace;">Windows Registry Editor Version <span style="">5.00</span>
&nbsp;
<span style="color: #000066; font-weight:bold;"><span style="">&#91;</span>HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Python<span style="">&#93;</span></span>
&nbsp;
<span style="color: #000066; font-weight:bold;"><span style="">&#91;</span>HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Python\PythonCore<span style="">&#93;</span></span>
&nbsp;
<span style="color: #000066; font-weight:bold;"><span style="">&#91;</span>HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Python\PythonCore\2.7<span style="">&#93;</span></span>
&nbsp;
<span style="color: #000066; font-weight:bold;"><span style="">&#91;</span>HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Python\PythonCore\2.7\InstallPath<span style="">&#93;</span></span>
@<span style="color: #000066; font-weight:bold;">=</span><span style="color: #933;">&quot;C:\\Users\\bennyn\\Desktop\\Instant Django\\django\\Python27&quot;</span>
&nbsp;
<span style="color: #000066; font-weight:bold;"><span style="">&#91;</span>HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Python\PythonCore\2.7\InstallPath\InstallGroup<span style="">&#93;</span></span>
@<span style="color: #000066; font-weight:bold;">=</span><span style="color: #933;">&quot;Python 2.7&quot;</span>
&nbsp;
<span style="color: #000066; font-weight:bold;"><span style="">&#91;</span>HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Python\PythonCore\2.7\PythonPath<span style="">&#93;</span></span>
@<span style="color: #000066; font-weight:bold;">=</span><span style="color: #933;">&quot;C:\\Users\\bennyn\\Desktop\\Instant Django\\django\\Python27\\Lib;C:\\Users\\bennyn\\Desktop\\Instant Django\\django\\Python27\\DLLs;C:\\Users\\bennyn\\Desktop\\Instant Django\\django\\Python27\\Lib\\lib-tk&quot;</span></pre></td></tr></table></div>

<p>Sobald diese Datei erstellt ist, kann man darauf klicken, wodurch die Registrierung durchgeführt wird. Danach muss man sich nur noch <a href="http://www.codegood.com/download/10/">MySQL-python-1.2.3.win32-py2.7.exe</a> von codegood.com herunterladen und ausführen. Sobald das passiert ist, kann man die Datei <b>start.bat</b> aus dem Instant Django-Ordner ausführen und dort <b>python</b> eingeben. Es öffnet sich die Python-Konsole, in welcher man nun <b>import MySQLdb</b> eingeben muss. Wirft dieser Import kein Fehler, so hat alles funktioniert!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bennyn.de/programmierung/python/mysql-fur-python-und-django-unter-windows.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Notiz &#8211; JDBC Datasource in JEE-Applikation hinzufügen</title>
		<link>http://www.bennyn.de/programmierung/java/notiz-jdbc-datasource-in-jee-applikation-hinzufugen.html</link>
		<comments>http://www.bennyn.de/programmierung/java/notiz-jdbc-datasource-in-jee-applikation-hinzufugen.html#comments</comments>
		<pubDate>Tue, 11 Jan 2011 10:01:53 +0000</pubDate>
		<dc:creator>bennyn</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Bean]]></category>
		<category><![CDATA[Connection]]></category>
		<category><![CDATA[Connector]]></category>
		<category><![CDATA[EJB]]></category>
		<category><![CDATA[Entity]]></category>
		<category><![CDATA[JDBC]]></category>
		<category><![CDATA[JEE]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[NetBeans]]></category>
		<category><![CDATA[Persistent]]></category>
		<category><![CDATA[Pool]]></category>
		<category><![CDATA[Ressource]]></category>
		<category><![CDATA[Servlet]]></category>
		<category><![CDATA[Session]]></category>

		<guid isPermaLink="false">http://www.bennyn.de/?p=2244</guid>
		<description><![CDATA[Hier eine Kurzbeschreibung, um in der Entwicklungsumgebung NetBeans 6.9.1 eine JDBC-Datasource für eine Java Enterprise-Applikation hinzuzufügen. Inklusive Database Mapping, Persistent Entities und Session Beans, die über Annotationen in einem Servlet verwendet werden können: &#8220;mysql-connector-java-5.1.13-bin.jar&#8221; in den lib-Ordner von GlassFish 3.0.1 kopieren GlassFish neustarten MySQL Connection-Pool in der GlassFish-Administrationsoberfläche anlegen JDBC Ressource (jdbc/name) in der GlassFish- [...]]]></description>
			<content:encoded><![CDATA[<p>Hier eine Kurzbeschreibung, um in der Entwicklungsumgebung NetBeans 6.9.1 eine <strong>JDBC-Datasource</strong> für eine <strong>Java Enterprise</strong>-Applikation hinzuzufügen. Inklusive Database Mapping, Persistent Entities und Session Beans, die über Annotationen in einem Servlet verwendet werden können:</p>
<ol>
<li>&#8220;mysql-connector-java-5.1.13-bin.jar&#8221; in den lib-Ordner von GlassFish 3.0.1 kopieren</li>
<li>GlassFish neustarten</li>
<li>MySQL Connection-Pool in der GlassFish-Administrationsoberfläche anlegen</li>
<li>JDBC Ressource (jdbc/name) in der GlassFish- Administrationsoberfläche anlegen</li>
<li>Entity Classes from Database (mit List-Collection) in NetBeans-Projekt generieren</li>
<li>New Persistence Unit in NetBeans-Projekt generieren</li>
<li>New Session Bean (ohne Interface) in NetBeans-Projekt erzeugen</li>
<li>New Servlet in NetBeans-Projekt erzeugen</li>
<li>SessionBean mit @EJB-Annotation verwenden</li>
</ol>
<p>Die JDBC Ressource muss diese Eigenschaften gesetzt haben:</p>
<blockquote><p>
portNumber<br />
databaseName<br />
serverName<br />
password<br />
user<br />
URL<br />
Url
</p></blockquote>
<p>Die URL wird folgendermaßen aufgebaut: <code>jdbc:mysql://hostname:port/databaseName</code>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bennyn.de/programmierung/java/notiz-jdbc-datasource-in-jee-applikation-hinzufugen.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Could not load JDBC driver class</title>
		<link>http://www.bennyn.de/programmierung/java/could-not-load-jdbc-driver-class.html</link>
		<comments>http://www.bennyn.de/programmierung/java/could-not-load-jdbc-driver-class.html#comments</comments>
		<pubDate>Tue, 14 Sep 2010 11:21:34 +0000</pubDate>
		<dc:creator>bennyn</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[applicationContext]]></category>
		<category><![CDATA[Connector]]></category>
		<category><![CDATA[dataSource]]></category>
		<category><![CDATA[driverClassName]]></category>
		<category><![CDATA[JDBC]]></category>
		<category><![CDATA[JEE]]></category>
		<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://www.bennyn.de/?p=1803</guid>
		<description><![CDATA[Beim Versuch eine Datenquelle (engl. datasource) in /WEB-INF/applicationContext.xml meiner Java Enterprise-Anwendung hinzuzufügen, lieferte mir die Ausgabe meines GlassFish Server 3 in NetBeans 6.9.1 diesen Fehler: org.springframework.beans.factory.BeanCreationException: Error creating bean with name &#8216;dataSource&#8217; defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Error setting property values; nested exception is org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are: PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property &#8216;driverClassName&#8217; threw [...]]]></description>
			<content:encoded><![CDATA[<p>Beim Versuch eine <strong>Datenquelle</strong> (engl. datasource) in <strong>/WEB-INF/applicationContext.xml</strong> meiner Java Enterprise-Anwendung hinzuzufügen, lieferte mir die Ausgabe meines <strong>GlassFish Server 3</strong> in NetBeans 6.9.1 diesen Fehler:</p>
<blockquote><p>
org.springframework.beans.factory.BeanCreationException: Error creating bean with name &#8216;dataSource&#8217; defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Error setting property values; nested exception is org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are: PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property &#8216;driverClassName&#8217; threw exception; nested exception is java.lang.IllegalStateException: Could not load JDBC driver class [com.mysql.jdbc.Driver]
</p></blockquote>
<p><span id="more-1803"></span><br />
Der Grund dafür war, dass der Treiber &#8220;com.mysql.jdbc.Driver&#8221; nicht gefunden werden konnte. Verursacht wurde dies durch diesen Eintrag:</p>
<p><b>/WEB-INF/applicationContext.xml</b></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;">...
    <span style="color: #808080; font-style: italic;">&lt;!-- ADD PERSISTENCE SUPPORT HERE (jpa, hibernate, etc) --&gt;</span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;dataSource&quot;</span></span>
<span style="color: #009900;">          <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.springframework.jdbc.datasource.DriverManagerDataSource&quot;</span></span>
<span style="color: #009900;">          <span style="color: #000066;">p:driverClassName</span>=<span style="color: #ff0000;">&quot;com.mysql.jdbc.Driver&quot;</span></span>
<span style="color: #009900;">          <span style="color: #000066;">p:url</span>=<span style="color: #ff0000;">&quot;jdbc:mysql://localhost/ksw&quot;</span></span>
<span style="color: #009900;">          <span style="color: #000066;">p:username</span>=<span style="color: #ff0000;">&quot;root&quot;</span></span>
<span style="color: #009900;">          <span style="color: #000066;">p:password</span>=<span style="color: #ff0000;">&quot;password&quot;</span></span>
<span style="color: #009900;">    <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
...</pre></td></tr></table></div>

<p>Die Eigenschaft &#8220;driverClassName&#8221; definiert den MySQL-Treiber, welcher aber nicht in der Applikation bekannt ist. Der entsprechende <a href="http://www.mysql.com/downloads/connector/j/" target="_blank">JDBC &#8211; MySQL Connector</a> (aktuell: mysql-connector-java-5.1.13) muss also heruntergeladen werden und dem NetBeans-Projekt in der Gruppe &#8220;Libraries&#8221; über &#8220;Add JAR/Folder&#8230;&#8221; bekannt gemacht werden.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bennyn.de/programmierung/java/could-not-load-jdbc-driver-class.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>phpMyAdmin auf Debian installieren</title>
		<link>http://www.bennyn.de/webanwendungen/virtual-server/phpmyadmin-auf-debian-installieren.html</link>
		<comments>http://www.bennyn.de/webanwendungen/virtual-server/phpmyadmin-auf-debian-installieren.html#comments</comments>
		<pubDate>Mon, 16 Aug 2010 23:06:35 +0000</pubDate>
		<dc:creator>bennyn</dc:creator>
				<category><![CDATA[Virtual Server]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[installieren]]></category>
		<category><![CDATA[konfigurieren]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[phpMyAdmin]]></category>

		<guid isPermaLink="false">http://www.bennyn.de/?p=1502</guid>
		<description><![CDATA[Vor der Installation von phpMyAdmin sollte zuerst ein MySQL-Daemon sowie ein Apache-Webserver installiert werden. Danach ist die Installation von phpMyAdmin ein Kinderspiel: 1 2 3 sudo apt-get install phpmyadmin sudo scp /etc/phpmyadmin/apache.conf /etc/apache2/conf.d/phpmyadmin.conf sudo /etc/init.d/apache2 reload Erklärung: phpMyAdmin installieren Konfigurationsdatei für phpMyAdmin dem Apache-Webserver bekannt machen Apache-Webserver Konfiguration neu laden Beispiel: phpmyadmin.conf # phpMyAdmin default [...]]]></description>
			<content:encoded><![CDATA[<p>Vor der Installation von <strong>phpMyAdmin</strong> sollte zuerst ein <strong>MySQL-Daemon</strong> sowie ein <strong>Apache-Webserver</strong> installiert werden. Danach ist die Installation von phpMyAdmin ein Kinderspiel:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> phpmyadmin
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">scp</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>phpmyadmin<span style="color: #000000; font-weight: bold;">/</span>apache.conf <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>apache2<span style="color: #000000; font-weight: bold;">/</span>conf.d<span style="color: #000000; font-weight: bold;">/</span>phpmyadmin.conf
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>apache2 reload</pre></td></tr></table></div>

<p><span id="more-1502"></span><br />
<b>Erklärung:</b></p>
<ol>
<li>phpMyAdmin installieren</li>
<li>Konfigurationsdatei für phpMyAdmin dem Apache-Webserver bekannt machen</li>
<li>Apache-Webserver Konfiguration neu laden</li>
</ol>
<p><b>Beispiel: phpmyadmin.conf</b></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># phpMyAdmin default Apache configuration</span>
&nbsp;
Alias <span style="color: #000000; font-weight: bold;">/</span>phpmyadmin <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>phpmyadmin
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;</span>Directory <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>phpmyadmin<span style="color: #000000; font-weight: bold;">&gt;</span>
	Options Indexes FollowSymLinks
	DirectoryIndex index.php
&nbsp;
	<span style="color: #666666; font-style: italic;"># Authorize for setup</span>
	<span style="color: #000000; font-weight: bold;">&lt;</span>Files setup.php<span style="color: #000000; font-weight: bold;">&gt;</span>
	    <span style="color: #666666; font-style: italic;"># For Apache 1.3 and 2.0</span>
	    <span style="color: #000000; font-weight: bold;">&lt;</span>IfModule mod_auth.c<span style="color: #000000; font-weight: bold;">&gt;</span>
		AuthType Basic
		AuthName <span style="color: #ff0000;">&quot;phpMyAdmin Setup&quot;</span>
		AuthUserFile <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>phpmyadmin<span style="color: #000000; font-weight: bold;">/</span>htpasswd.setup
	    <span style="color: #000000; font-weight: bold;">&lt;/</span>IfModule<span style="color: #000000; font-weight: bold;">&gt;</span>
	    <span style="color: #666666; font-style: italic;"># For Apache 2.2</span>
	    <span style="color: #000000; font-weight: bold;">&lt;</span>IfModule mod_authn_file.c<span style="color: #000000; font-weight: bold;">&gt;</span>
		AuthType Basic
		AuthName <span style="color: #ff0000;">&quot;phpMyAdmin Setup&quot;</span>
		AuthUserFile <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>phpmyadmin<span style="color: #000000; font-weight: bold;">/</span>htpasswd.setup
	    <span style="color: #000000; font-weight: bold;">&lt;/</span>IfModule<span style="color: #000000; font-weight: bold;">&gt;</span>
	    Require valid-user
	<span style="color: #000000; font-weight: bold;">&lt;/</span>Files<span style="color: #000000; font-weight: bold;">&gt;</span>
	<span style="color: #000000; font-weight: bold;">&lt;</span>IfModule mod_php4.c<span style="color: #000000; font-weight: bold;">&gt;</span>
		AddType application<span style="color: #000000; font-weight: bold;">/</span>x-httpd-php .php
&nbsp;
		php_flag magic_quotes_gpc Off
		php_flag track_vars On
		php_flag register_globals Off
		php_value include_path .
	<span style="color: #000000; font-weight: bold;">&lt;/</span>IfModule<span style="color: #000000; font-weight: bold;">&gt;</span>
	<span style="color: #000000; font-weight: bold;">&lt;</span>IfModule mod_php5.c<span style="color: #000000; font-weight: bold;">&gt;</span>
		AddType application<span style="color: #000000; font-weight: bold;">/</span>x-httpd-php .php
&nbsp;
		php_flag magic_quotes_gpc Off
		php_flag track_vars On
		php_flag register_globals Off
		php_value include_path .
	<span style="color: #000000; font-weight: bold;">&lt;/</span>IfModule<span style="color: #000000; font-weight: bold;">&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;/</span>Directory<span style="color: #000000; font-weight: bold;">&gt;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.bennyn.de/webanwendungen/virtual-server/phpmyadmin-auf-debian-installieren.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

