<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="http://sqlzoo.net/w/skins/common/feed.css?303"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://sqlzoo.net/w/index.php?title=SQL_from_Java&amp;feed=atom&amp;action=history</id>
		<title>SQL from Java - Revision history</title>
		<link rel="self" type="application/atom+xml" href="http://sqlzoo.net/w/index.php?title=SQL_from_Java&amp;feed=atom&amp;action=history"/>
		<link rel="alternate" type="text/html" href="http://sqlzoo.net/w/index.php?title=SQL_from_Java&amp;action=history"/>
		<updated>2013-05-20T17:17:59Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.20.4</generator>

	<entry>
		<id>http://sqlzoo.net/w/index.php?title=SQL_from_Java&amp;diff=1869&amp;oldid=prev</id>
		<title>Connor: Created page with &quot;&lt;p&gt;You can connect to an SQL engine using JDBC. You will need to obtain a JDBC driver from the appropriate database. &lt;/p&gt; &lt;ul&gt; &lt;li&gt;The example given is based on the MySQL JDBC...&quot;</title>
		<link rel="alternate" type="text/html" href="http://sqlzoo.net/w/index.php?title=SQL_from_Java&amp;diff=1869&amp;oldid=prev"/>
				<updated>2012-07-19T10:48:06Z</updated>
		
		<summary type="html">&lt;p&gt;Created page with &amp;quot;&amp;lt;p&amp;gt;You can connect to an SQL engine using JDBC. You will need to obtain a JDBC driver from the appropriate database. &amp;lt;/p&amp;gt; &amp;lt;ul&amp;gt; &amp;lt;li&amp;gt;The example given is based on the MySQL JDBC...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&amp;lt;p&amp;gt;You can connect to an SQL engine using JDBC. You will need to obtain&lt;br /&gt;
a JDBC driver from the appropriate database.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;The example given is based on the MySQL JDBC Connector/J which may be found&lt;br /&gt;
at [http://dev.mysql.com/downloads/connector/j/ MySQL]&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Extract the MySQL Connector/J into a directory C:\thingies.&lt;br /&gt;
(If you know what you are doing you will put this in your classpath.)&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;The program connects to mysql server running on my computer - the user name&lt;br /&gt;
and password is valid - you may use it too.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;More examples at [http://progzoo.net/wiki/Read_From_a_Database http://progzoo.net/wiki/Read_From_a_Database]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;You need to compile and execute the java from the command prompt:&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;padding:1em;border-style:solid;background-color:rgb(192,192,192)&amp;quot;&amp;gt;javac CIA.java&lt;br /&gt;
java -classpath &amp;quot;C:/thingies/mysql-connector-java-2.0.14;.&amp;quot; &amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre style=&amp;quot;padding:1em;border-style:solid;background-color:rgb(192,192,192)&amp;quot;&amp;gt;/* CIA.java&lt;br /&gt;
   From http://sqlzoo.net By Andrew Cumming&lt;br /&gt;
*/&lt;br /&gt;
import java.sql.*;&lt;br /&gt;
public class CIA{&lt;br /&gt;
  public static void main(String[] args){&lt;br /&gt;
    Connection myCon;&lt;br /&gt;
    Statement myStmt;&lt;br /&gt;
    try{&lt;br /&gt;
      Class.forName(&amp;quot;com.mysql.jdbc.Driver&amp;quot;).newInstance();&lt;br /&gt;
      // Connect to an instance of mysql with the follow details:&lt;br /&gt;
      // machine address: pc236nt.napier.ac.uk&lt;br /&gt;
      // database       : gisq&lt;br /&gt;
      // user name      : scott&lt;br /&gt;
      // password       : tiger&lt;br /&gt;
      myCon = DriverManager.getConnection(&lt;br /&gt;
              &amp;quot;jdbc:mysql://pc236nt.napier.ac.uk/gisq&amp;quot;,&lt;br /&gt;
              &amp;quot;scott&amp;quot;,&amp;quot;tiger&amp;quot;);&lt;br /&gt;
      myStmt = myCon.createStatement();&lt;br /&gt;
      ResultSet result = myStmt.executeQuery(&lt;br /&gt;
         &amp;quot;SELECT * FROM cia WHERE population&amp;gt;200000000&amp;quot;);&lt;br /&gt;
      while (result.next()){&lt;br /&gt;
        System.out.println(result.getString(&amp;quot;name&amp;quot;));&lt;br /&gt;
      }&lt;br /&gt;
      myCon.close();&lt;br /&gt;
    }&lt;br /&gt;
    catch (Exception sqlEx){&lt;br /&gt;
      System.err.println(sqlEx);&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;It should respond with the names of four countries.&amp;lt;/p&amp;gt;&lt;/div&gt;</summary>
		<author><name>Connor</name></author>	</entry>

	</feed>