<?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 Informatikblog &#187; MySQL</title>
	<atom:link href="http://www.informatik-blog.net/tag/mysql/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.informatik-blog.net</link>
	<description>Informatik &#38; Co.</description>
	<lastBuildDate>Mon, 28 Jun 2010 19:43:30 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>MySQL Verbindung aufbauen, Query senden, abfragen</title>
		<link>http://www.informatik-blog.net/2009/01/28/mysql-verbindung-aufbauen-query-senden-abfragen/</link>
		<comments>http://www.informatik-blog.net/2009/01/28/mysql-verbindung-aufbauen-query-senden-abfragen/#comments</comments>
		<pubDate>Wed, 28 Jan 2009 21:58:51 +0000</pubDate>
		<dc:creator>Emanuel</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Array]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Query]]></category>
		<category><![CDATA[ResultSet]]></category>
		<category><![CDATA[ReturnQuery]]></category>

		<guid isPermaLink="false">http://www.informatik-blog.net/?p=462</guid>
		<description><![CDATA[

Mithilfe des JDBC ist es möglich MySQL Verbindungen aufzubauen und Informationen zu übermitteln und abzufragen. Wie das Beispiel zeigt, senden wir ein einfaches Query an die Datenbank und fragen dieses dann ab. Selbstverständlich ist MySQL weitaus komplexer, worauf sich die Sektion &#8220;SQL&#8221; spezialisiert.
Um ein einfaches Query abzusenden kann folgende Klasse verwendet werden:

hier nun die Klasse [...]]]></description>
			<content:encoded><![CDATA[
<!-- google_ad_section_start -->
<p>Mithilfe des JDBC ist es möglich MySQL Verbindungen aufzubauen und Informationen zu übermitteln und abzufragen. Wie das Beispiel zeigt, senden wir ein einfaches Query an die Datenbank und fragen dieses dann ab. Selbstverständlich ist MySQL weitaus komplexer, worauf sich die Sektion &#8220;SQL&#8221; spezialisiert.</p>
<p>Um ein einfaches Query abzusenden kann folgende Klasse verwendet werden:</p>
<p><span id="more-462"></span></p>
<p>hier nun die Klasse MySQL .java</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">mysqltest</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.sql.Connection</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.sql.DriverManager</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.sql.ResultSet</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.sql.SQLException</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.sql.Statement</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> MySQL <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> Username <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;root&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> Password <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Passwort&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> <span style="color: #003399;">Driver</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;com.mysql.jdbc.Driver&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> <span style="color: #003399;">URL</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;jdbc:mysql://mysql.host.net:3306/datenbank&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">Connection</span> connection<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> MySQL<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">Connect</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
   <span style="color: #666666; font-style: italic;">/* Sollte der Konstruktur ohne argumente aufgerufen werden, werden die in der klasse genutzten Werte genommen. */</span>
&nbsp;
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> MySQL<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> user, <span style="color: #003399;">String</span> pass<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">Username</span> <span style="color: #339933;">=</span> user<span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">Password</span> <span style="color: #339933;">=</span> pass<span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">Connect</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;">/* Sollte der Konstruktur mit den Argumenten user und pass aufgerufen werden, werden diese definiert und dann Verbunden. */</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> Close<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">connection</span> <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">connection</span>.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Exception</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/* Die Funktion Close() schließt das Query um den Speicher wieder frei zu geben */</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> Connect<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">Class</span>.<span style="color: #006633;">forName</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #003399;">Driver</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">connection</span> <span style="color: #339933;">=</span> <span style="color: #003399;">DriverManager</span>.<span style="color: #006633;">getConnection</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #003399;">URL</span>,
                    <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">Username</span>, <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">Password</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Exception</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            e.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Error Connecting with User:&quot;</span> <span style="color: #339933;">+</span> Username <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot; and Password:&quot;</span> <span style="color: #339933;">+</span> Password<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/* Connect registriert den JDBC Treiber und versucht eine Verbindung herzustellen. Sollte dies nicht möglich sein, wird eine Exception ausgelöst */</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">boolean</span> isConnected<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #003399;">ResultSet</span> rs <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">ReturnQuery</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT 1;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>rs <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
            <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>rs.<span style="color: #006633;">next</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
            <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Exception</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/* frägt ein einfaches Query ab, welches &quot;1&quot; zurück liefert, falls man verbunden ist */</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">ResultSet</span> ReturnQuery<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> query<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #003399;">Statement</span> stmt <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">connection</span>.<span style="color: #006633;">createStatement</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #003399;">ResultSet</span> rs <span style="color: #339933;">=</span> stmt.<span style="color: #006633;">executeQuery</span><span style="color: #009900;">&#40;</span>query<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000000; font-weight: bold;">return</span> rs<span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">SQLException</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #003399;">System</span>.<span style="color: #006633;">err</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>e.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/* Sendet ein Query und erwartet eine Rückgabe in Form eines ResultSet */</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">boolean</span> RunQuery<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> query<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #003399;">Statement</span> stmt <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">connection</span>.<span style="color: #006633;">createStatement</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000000; font-weight: bold;">return</span> stmt.<span style="color: #006633;">execute</span><span style="color: #009900;">&#40;</span>query<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Exception</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #666666; font-style: italic;">//  e.printStackTrace();</span>
            <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #666666; font-style: italic;">/* Führt das query aus, erwartet aber keine Rückantwort des Servers. */</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>um in MySQL zu verbinden wird diese klasse folgendermaßen aufgerufen:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">mysqltest</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">MySQL</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
 *
 * @author li
 */</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Main <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        db <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> MySQL<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #003399;">ResultSet</span> rs <span style="color: #339933;">=</span> db.<span style="color: #006633;">ReturnQuery</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;select count(*) as num from test where a='1'&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span>rs.<span style="color: #006633;">next</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            countRows <span style="color: #339933;">=</span> rs.<span style="color: #006633;">getInt</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;num&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>countRows<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<!-- google_ad_section_end -->
]]></content:encoded>
			<wfw:commentRss>http://www.informatik-blog.net/2009/01/28/mysql-verbindung-aufbauen-query-senden-abfragen/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Datenbankverbindung herstellen</title>
		<link>http://www.informatik-blog.net/2009/01/27/datenbankverbindung-herstellen/</link>
		<comments>http://www.informatik-blog.net/2009/01/27/datenbankverbindung-herstellen/#comments</comments>
		<pubDate>Tue, 27 Jan 2009 22:16:40 +0000</pubDate>
		<dc:creator>Emanuel</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Datenbanken]]></category>
		<category><![CDATA[JDBC]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Oracle]]></category>

		<guid isPermaLink="false">http://www.informatik-blog.net/?p=410</guid>
		<description><![CDATA[

In Java gibt es für die Datenbankverbindung die Klasse jdbc, welche für Java Database Connectivity steht. Mithilfe dieser Klasse ist es möglich zu einer vielzahl unterschiedlichen Datenbanken zu verbinden und zu verwalten. In folgenden Beispielen wird gezeigt, wie man eine Verbindung zu Oracle und zu MySQL herstellt.


/**
* Verbindung zu Oracle
*
* @param server 
* @param port [...]]]></description>
			<content:encoded><![CDATA[
<!-- google_ad_section_start -->
<p>In Java gibt es für die Datenbankverbindung die Klasse jdbc, welche für Java Database Connectivity steht. Mithilfe dieser Klasse ist es möglich zu einer vielzahl unterschiedlichen Datenbanken zu verbinden und zu verwalten. In folgenden Beispielen wird gezeigt, wie man eine Verbindung zu Oracle und zu MySQL herstellt.</p>
<p><span id="more-410"></span></p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #008000; font-style: italic; font-weight: bold;">/**
* Verbindung zu Oracle
*
* @param server 
* @param port 
* @param serviceName 
* @param user
* @param password 
* @return Connection-Objekt 
*/</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #003399;">Connection</span> connectOracle<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> server, <span style="color: #003399;">String</span> port, <span style="color: #003399;">String</span> serviceName, <span style="color: #003399;">String</span> user, <span style="color: #003399;">String</span> password<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #003399;">Connection</span> conn <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
<span style="color: #666666; font-style: italic;">// Oracle Treiber laden und registrieren</span>
<span style="color: #003399;">DriverManager</span>.<span style="color: #006633;">registerDriver</span> <span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> oracle.<span style="color: #006633;">jdbc</span>.<span style="color: #006633;">driver</span>.<span style="color: #006633;">OracleDriver</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// Verbinden</span>
<span style="color: #003399;">String</span> str <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;jdbc:oracle:thin:@&quot;</span> <span style="color: #339933;">+</span> server <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;:&quot;</span> <span style="color: #339933;">+</span> port <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;:&quot;</span> <span style="color: #339933;">+</span> serviceName<span style="color: #339933;">;</span>
conn <span style="color: #339933;">=</span> <span style="color: #003399;">DriverManager</span>.<span style="color: #006633;">getConnection</span><span style="color: #009900;">&#40;</span>str, user, password<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">SQLException</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
e.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">return</span> conn<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Ebenso ist es problemlos möglich eine Verbindung zu MySQL herzustellen, wie folgendes Beispiel zeigt.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #008000; font-style: italic; font-weight: bold;">/**
* Verbindungsaufbau zu MySQL-Datenbank
*
* @param server 
* @param port 
* @param database 
* @param user 
* @param password 
* @return Connection-Objekt 
*/</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #003399;">Connection</span> connectMySQL<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> server, <span style="color: #003399;">String</span> port, <span style="color: #003399;">String</span> database, <span style="color: #003399;">String</span> user, <span style="color: #003399;">String</span> password<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #003399;">Connection</span> conn <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
<span style="color: #666666; font-style: italic;">// Treiber laden und registrieren</span>
<span style="color: #003399;">DriverManager</span>.<span style="color: #006633;">registerDriver</span> <span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> com.<span style="color: #006633;">mysql</span>.<span style="color: #006633;">jdbc</span>.<span style="color: #003399;">Driver</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// Verbinden</span>
<span style="color: #003399;">String</span> str <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;jdbc:mysql://&quot;</span> <span style="color: #339933;">+</span> server <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;:&quot;</span> <span style="color: #339933;">+</span> port <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;/&quot;</span> <span style="color: #339933;">+</span> database<span style="color: #339933;">;</span>
conn <span style="color: #339933;">=</span> <span style="color: #003399;">DriverManager</span>.<span style="color: #006633;">getConnection</span><span style="color: #009900;">&#40;</span>str, user, password<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">SQLException</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
e.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">return</span> conn<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Wie man sieht, ist es sehr schnell und einfach möglich eine Datenbankverbindung herzustellen.<br />
JDBC unterstützt folgene Datenbanken:<br />
Woof, 4D JDBC Driver, JDBC NetServer, ANTs ODBC Driver, Open/A for Java, Jturbo driver, Ashpool JDBC Driver, aveConnect, Attunity Connect (server), Axion JDBC driver , BASIS JDBC Driver, BBj Data Server, jdbcKona, WebLogic application server, Birdstep RDM JDBC Driver, jdbc Pool, InterClient, Borland Data Gateway for Java, VisiChannel for JDBC, tcACCESS, aveConnect, JSQL/Ingres, DBMaker JDBC-ODBC Bridge, CONNX, Sequoia JDBC driver, Corel Paradox JDBC driver, Daffodil DB Driver, DataDirect SequeLink JAVA (server), Connect JDBC (type 4), Dharma JDBC SDK, JDBC SDK Lite, Dharma SQL, Mckoi SQL JDBC Driver, JDBC-ODBC Bridge, Hot Sockets JDBC SDK (server), UniVerse JDBC driver, Advantage JDBC driver, FairCom JDBC Driver, Firebird JDBC Driver, FirstSQL/J JDBC, FormWeb JDBC, JDBC2, MB Foster Universal Server, JDBC 1.x (Type 4), FrontBase JDBC driver, SESAM JDBC driver, eTools JDBC, GemStone/J, DatAccess, SQLBase JDBC driver, GWE MYSQL JDBC driver, H2 JDBC driver, High-Availability JDBC proxy, NonStop SQL/MX JDBC, DABroker Driver for Java (server), HiT JDBC, HOBLink J-DRDA, HXTT DBF driver, HXTT Text driver, HXTT Paradox, HXTT Excel driver, HXTT Access driver, hsql JDBC driver, Hummingbird Met@Data, SearchServer JDBC driver, JDBC driver for LanDiBase, DB2 Connect, JDBC Toolbox, JTOpen, Informix JDBC Driver, Lotus Domino Driver for JDBC, IDS JDBC driver, OPENjdbc, Imaginary JDBC, i-net *, dtF/SQL JDBC Driver for Macintosh, jadoZoom, WebFOCUS BI server, InterClient, Essentia JDBC, Caché JDBC Driver, livestore (JDBC cache), Intelligent Adapters, Data Adapters, JET Proxy, JDataConnect, JSQLConnect JSecureConnect, StelsCSV JDBC Driver, StelsEngine JDBC Driver, StelsDBF, StelsXML, StelsMDB JDBC Driver, jTDS JDBC Driver, jxPG JDBC driver, jdbshare, Kdb+ JDBC driver, DUALITY JDBC Proxy, Matisse JDBC driver, JDBC Driver for Teradata, Microsoft SQL Server JDBC Driver, Mimer JDBC, Minisoft JDBC driver, JDBC for Eloquence, MmMySQL JDBC Driver, Teradata JDBC Driver, Teradata JDBC Gateway, SQL-Surfer, JTurbo, NewCoTec JDBC-Treiber, xlSQL, RemoteDB Gateway Server JDBC driver (server), Database Manager for Netware (ODBX-JDBC), LDAP JDBC Driver, ODBC/JDBC Driver Manager for Netware, RmiJdbc, OpenAccess JDBC SDK, OpenAccess JDBC SDK, OpenLink Universal Data Access Driver Suite for JDBC, OpenLink Virtuoso (server), Livelink Collections Server JDBC Driver, Livelink Collections Server JDBC Driver, Enlist: Report Server, Enquire: Directory Server, Ensure: Synchronization Server, Pervasive JDBC driver, PointBase JDBC, PostgreSQL JDBC driver, Apptivity Server, QED JDBC Driver, Recital JDBC Developer, RDBMS Linter SQL ODBC driver, SCO SQL Retriever, SAP DB JDBC Driver, SAS/SHARExNET JDBC interface, CodeBase FOR JDBC, SimbaEngine SDK, dtF/SQL JDBC Driver, SmallSQL JDBC driver, SocketJdbc, Type 4, LDAP Directory JDBC Driver, ADABAS JDBC Client, JDataConnect, StarSQL for Java, Sunopsis JDBC for XML, jCONNECT, EnterpriseCONNECT Gateway (server), Synergy/DE, SQL Connection, ThinkSQL JDBC driver, ThinAccess, U/SQL ODBC/JDBC Gateway, VORTEXjdbc, VORTEXjdbc, Vista JDBC driver, Vista JDBC driver usw.</p>
<!-- google_ad_section_end -->
]]></content:encoded>
			<wfw:commentRss>http://www.informatik-blog.net/2009/01/27/datenbankverbindung-herstellen/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
