提交 e979821e authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Java 7 and Android load drivers from META-INF/services/java.sql.Driver

上级 f585c6e9
...@@ -1065,7 +1065,6 @@ import java.sql.*; ...@@ -1065,7 +1065,6 @@ import java.sql.*;
import java.util.*; import java.util.*;
public class Test { public class Test {
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
Class.forName("org.h2.Driver");
String url = "jdbc:h2:~/test"; String url = "jdbc:h2:~/test";
Properties prop = new Properties(); Properties prop = new Properties();
prop.setProperty("user", "sa"); prop.setProperty("user", "sa");
...@@ -1083,7 +1082,6 @@ public class Test { ...@@ -1083,7 +1082,6 @@ public class Test {
} }
</pre> </pre>
<p> <p>
This example requires Java 1.6.
When using Swing, use <code>javax.swing.JPasswordField</code>. When using Swing, use <code>javax.swing.JPasswordField</code>.
</p> </p>
......
...@@ -169,7 +169,6 @@ Reference: ...@@ -169,7 +169,6 @@ Reference:
<h2><a href="tutorial.html#connecting_using_jdbc">Using the JDBC API</a></h2> <h2><a href="tutorial.html#connecting_using_jdbc">Using the JDBC API</a></h2>
<pre> <pre>
Class.forName("org.h2.Driver");
Connection conn = DriverManager. Connection conn = DriverManager.
getConnection("jdbc:h2:~/test"); getConnection("jdbc:h2:~/test");
conn.close(); conn.close();
......
...@@ -117,7 +117,6 @@ and the database URL starts with <code>jdbc:h2:</code>. ...@@ -117,7 +117,6 @@ and the database URL starts with <code>jdbc:h2:</code>.
To connect to a database using JDBC, use the following code: To connect to a database using JDBC, use the following code:
</p> </p>
<pre> <pre>
Class.forName("org.h2.Driver");
Connection conn = DriverManager.getConnection("jdbc:h2:~/test", "sa", ""); Connection conn = DriverManager.getConnection("jdbc:h2:~/test", "sa", "");
</pre> </pre>
......
...@@ -669,7 +669,6 @@ and user passwords are case sensitive. Here is an example to connect to a ...@@ -669,7 +669,6 @@ and user passwords are case sensitive. Here is an example to connect to a
password-encrypted database: password-encrypted database:
</p> </p>
<pre> <pre>
Class.forName("org.h2.Driver");
String url = "jdbc:h2:~/test;CIPHER=AES"; String url = "jdbc:h2:~/test;CIPHER=AES";
String user = "sa"; String user = "sa";
String pwds = "filepwd userpwd"; String pwds = "filepwd userpwd";
......
...@@ -456,7 +456,6 @@ import java.sql.*; ...@@ -456,7 +456,6 @@ import java.sql.*;
public class Test { public class Test {
public static void main(String[] a) public static void main(String[] a)
throws Exception { throws Exception {
Class.forName("org.h2.Driver");
Connection conn = DriverManager. Connection conn = DriverManager.
getConnection("jdbc:h2:~/test", "sa", ""); getConnection("jdbc:h2:~/test", "sa", "");
// add application code here // add application code here
...@@ -465,8 +464,7 @@ public class Test { ...@@ -465,8 +464,7 @@ public class Test {
} }
</pre> </pre>
<p> <p>
This code first loads the driver (<code>Class.forName(...)</code>) This code opens a connection (using <code>DriverManager.getConnection()</code>).
and then opens a connection (using <code>DriverManager.getConnection()</code>).
The driver name is <code>"org.h2.Driver"</code>. The driver name is <code>"org.h2.Driver"</code>.
The database URL always needs to start with <code>jdbc:h2:</code> The database URL always needs to start with <code>jdbc:h2:</code>
to be recognized by this database. The second parameter in the <code>getConnection()</code> call to be recognized by this database. The second parameter in the <code>getConnection()</code> call
...@@ -867,7 +865,6 @@ String url = "jdbc:h2:/data/data/" + ...@@ -867,7 +865,6 @@ String url = "jdbc:h2:/data/data/" +
";FILE_LOCK=FS" + ";FILE_LOCK=FS" +
";PAGE_SIZE=1024" + ";PAGE_SIZE=1024" +
";CACHE_SIZE=8192"; ";CACHE_SIZE=8192";
Class.forName("org.h2.Driver");
conn = DriverManager.getConnection(url); conn = DriverManager.getConnection(url);
... ...
</pre> </pre>
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论