<?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>Sybase数据库技术，数据库恢复专家 &#187; Informix</title>
	<atom:link href="http://www.dbainfo.net/tag/informix/feed" rel="self" type="application/rss+xml" />
	<link>https://www.dbainfo.net</link>
	<description>提供Sybase ASE及Sybase SQL Anywhere数据库修复服务，电话：13811580958(微信)，QQ：289965371！We have many years of experience in recovering data from damanged Sybase devices. Contact us by Phone: +86 13811580958 Wechat: 13811580958 Email: 289965371@qq.com</description>
	<lastBuildDate>Sat, 14 Jun 2025 16:28:02 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>java连接数据库Oracle,DB2,SQL Server,Sybase,Informix,MySQL,PostgreSQL</title>
		<link>https://www.dbainfo.net/java-connect-url-for-oracle-db2-sql-sybase-informix-mysql-pgsql.htm</link>
		<comments>https://www.dbainfo.net/java-connect-url-for-oracle-db2-sql-sybase-informix-mysql-pgsql.htm#comments</comments>
		<pubDate>Fri, 17 Sep 2010 08:03:01 +0000</pubDate>
		<dc:creator>dbainfo</dc:creator>
				<category><![CDATA[Miscellaneous]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[SQL SERVER]]></category>
		<category><![CDATA[Sybase ASE]]></category>
		<category><![CDATA[DB2]]></category>
		<category><![CDATA[Informix]]></category>
		<category><![CDATA[jdbc]]></category>
		<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[sybase]]></category>

		<guid isPermaLink="false">http://www.dbainfo.net/?p=1847</guid>
		<description><![CDATA[Java数据库连接（JDBC）由一组用 Java 编程语言编写的类和接口组成。JDBC 为工具/数据库开发人员提供了一个标准的 API，使他们能够用纯Java API 来编写数据库应用程序。然而各个开发商的接口并不完全相同，所以开发环境的变化会带来一定的配置变化。本文主要集合了不同数据库的连接方式。 一、连接各种数据库方式速查表 　　 下面罗列了各种数据库使用JDBC连接的方式，可以作为一个手册使用。 　　 1、Oracle8/8i/9i数据库（thin模式） Java代码 &#160; Class.forName(&#34;oracle.jdbc.driver.OracleDriver&#34;).newInstance();&#160; &#160; String url=&#34;jdbc:oracle:thin:@localhost:1521:orcl&#34;; //orcl为数据库的SID&#160; &#160; String user=&#34;test&#34;;&#160; &#160; String password=&#34;test&#34;;&#160; &#160; Connection conn= DriverManager.getConnection(url,user,password);&#160; &#160; &#160; 　　 2、DB2数据库 Java代码 &#160; Class.forName(&#34;com.ibm.db2.jdbc.app.DB2Driver&#34;).newInstance();&#160; &#160; String url=&#34;jdbc:db2://localhost:5000/sample&#34;; //sample为你的数据库名&#160; &#160; String user=&#34;admin&#34;;&#160; &#160; String password=&#34;&#34;;&#160; &#160; Connection conn= DriverManager.getConnection(url,user,password);&#160; &#160; &#160; 　　 3、SQL Server7.0/2000数据库 [...]]]></description>
			<content:encoded><![CDATA[<p>Java数据库连接（JDBC）由一组用 Java 编程语言编写的类和接口组成。JDBC 为工具/数据库开发人员提供了一个标准的 API，使他们能够用纯Java API 来编写数据库应用程序。然而各个开发商的接口并不完全相同，所以开发环境的变化会带来一定的配置变化。本文主要集合了不同数据库的连接方式。 </p>
<p>	一、连接各种数据库方式速查表 <br />
	　　 下面罗列了各种数据库使用JDBC连接的方式，可以作为一个手册使用。 <br />
	　　 1、Oracle8/8i/9i数据库（thin模式） <br />
	Java代码 &nbsp;<br />
	Class.forName(&quot;oracle.jdbc.driver.OracleDriver&quot;).newInstance();&nbsp; &nbsp;<br />
	String url=&quot;jdbc:oracle:thin:@localhost:1521:orcl&quot;; //orcl为数据库的SID&nbsp; &nbsp;<br />
	String user=&quot;test&quot;;&nbsp; &nbsp;<br />
	String password=&quot;test&quot;;&nbsp; &nbsp;<br />
	Connection conn= DriverManager.getConnection(url,user,password);&nbsp; &nbsp;<br />
	&nbsp;<br />
	　　 2、DB2数据库 <br />
	Java代码 &nbsp;<br />
	Class.forName(&quot;com.ibm.db2.jdbc.app.DB2Driver&quot;).newInstance();&nbsp; &nbsp;<br />
	String url=&quot;jdbc:db2://localhost:5000/sample&quot;; //sample为你的数据库名&nbsp; &nbsp;<br />
	String user=&quot;admin&quot;;&nbsp; &nbsp;<br />
	String password=&quot;&quot;;&nbsp; &nbsp;<br />
	Connection conn= DriverManager.getConnection(url,user,password);&nbsp; &nbsp;<br />
	&nbsp;<span id="more-1847"></span><br />
	　　 3、SQL Server7.0/2000数据库</p>
<blockquote>
<p>Java代码 &nbsp;<br />
		Class.forName(&quot;com.microsoft.jdbc.sqlserver.SQLServerDriver&quot;).newInstance();&nbsp; &nbsp;<br />
		String url=&quot;jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=mydb&quot;;&nbsp; //mydb为数据库&nbsp; &nbsp;<br />
		String user=&quot;sa&quot;;&nbsp; &nbsp;<br />
		String password=&quot;&quot;;&nbsp; &nbsp;<br />
		Connection conn= DriverManager.getConnection(url,user,password);&nbsp; &nbsp;</p>
<p>		对于SQL Server2005/2008数据库 <br />
		Class.forName(&quot;com.microsoft.sqlserver.jdbc.SQLServerDriver&quot;).newInstance();&nbsp; &nbsp;<br />
		String url=&quot;jdbc:sqlserver://localhost:1433;DatabaseName=mydb&quot;; //mydb为数据库&nbsp; &nbsp;<br />
		String user=&quot;sa&quot;;&nbsp; &nbsp;<br />
		String password=&quot;&quot;;&nbsp; &nbsp;<br />
		Connection conn= DriverManager.getConnection(url,user,password);&nbsp;&nbsp;</p>
</blockquote>
<p>
	　　 4、Sybase数据库</p>
<blockquote>
<p>Java代码 &nbsp;<br />
		Class.forName(&quot;com.sybase.jdbc.SybDriver&quot;).newInstance();&nbsp; &nbsp;<br />
		String url =&quot; jdbc:sybase:Tds:localhost:5007/myDB&quot;;//Sybase ASE端口号为：5007，连接的数据库名称为：myDB&nbsp; &nbsp;<br />
		Properties sysProps = System.getProperties();&nbsp; &nbsp;<br />
		SysProps.put(&quot;user&quot;,&quot;userid&quot;);&nbsp; &nbsp;<br />
		SysProps.put(&quot;password&quot;,&quot;user_password&quot;);&nbsp; &nbsp;<br />
		Connection conn= DriverManager.getConnection(url, SysProps);</p>
<p>		Sybase ASE 12.5.x使用jconn2.jar连接数据库<br />
		Class.forName(&quot;com.sybase.jdbc2.jdbc.SybDriver&quot;).newInstance();<br />
		String url = &quot;jdbc:sybase:Tds:localhost:5007/myDB&quot;;//Sybase ASE端口号为：5007，连接的数据库名称为：myDB <br />
		Properties sysProps = System.getProperties();<br />
		sysProps.put(&quot;user&quot;, &quot;sa&quot;); // 设置数据库访问用户名<br />
		sysProps.put(&quot;password&quot;, &quot;sybase&quot;); // 密码<br />
		Connection conn = DriverManager.getConnection(url, sysProps);</p>
<p>		Sybase ASE 15.x使用jconn3.jar连接数据库<br />
		Class.forName(&quot;com.sybase.jdbc3.jdbc.SybDriver&quot;).newInstance();<br />
		String url = &quot;jdbc:sybase:Tds:localhost:5007/myDB&quot;;//Sybase ASE端口号为：5007，连接的数据库名称为：myDB <br />
		Properties sysProps = System.getProperties();<br />
		sysProps.put(&quot;user&quot;, &quot;sa&quot;); // 设置数据库访问用户名<br />
		sysProps.put(&quot;password&quot;, &quot;sybase&quot;); // 密码<br />
		Connection conn = DriverManager.getConnection(url, sysProps);</p>
</blockquote>
<p>
	　　 5、Informix数据库 <br />
	Java代码 &nbsp;<br />
	Class.forName(&quot;com.informix.jdbc.IfxDriver&quot;).newInstance();&nbsp; &nbsp;<br />
	String url = &quot;jdbc:informix-sqli://123.45.67.89:1533/myDB:INFORMIXSERVER=myserver;&nbsp; &nbsp;<br />
	user=testuser;password=testpassword&quot;; //myDB为数据库名&nbsp; &nbsp;<br />
	Connection conn= DriverManager.getConnection(url);&nbsp; &nbsp;<br />
	&nbsp;<br />
	　　 6、MySQL数据库 <br />
	Java代码 &nbsp;<br />
	Class.forName(&quot;org.gjt.mm.mysql.Driver&quot;).newInstance();&nbsp; &nbsp;<br />
	String url =&quot;jdbc:mysql://localhost/myDB?user=soft&amp;password=soft1234&amp;useUnicode=true&amp;characterEncoding=8859_1&quot;&nbsp; &nbsp;<br />
	//myDB为数据库名&nbsp; &nbsp;<br />
	Connection conn= DriverManager.getConnection(url);&nbsp; &nbsp;<br />
	&nbsp;<br />
	　　 7、PostgreSQL数据库 <br />
	Java代码 &nbsp;<br />
	Class.forName(&quot;org.postgresql.Driver&quot;).newInstance();&nbsp; &nbsp;<br />
	String url =&quot;jdbc:postgresql://localhost/myDB&quot; //myDB为数据库名&nbsp; &nbsp;<br />
	String user=&quot;myuser&quot;;&nbsp; &nbsp;<br />
	String password=&quot;mypassword&quot;;&nbsp; &nbsp;<br />
	Connection conn= DriverManager.getConnection(url,user,password);&nbsp; &nbsp;<br />
	&nbsp;<br />
	　　 8、access数据库直连用ODBC的 <br />
	Java代码 &nbsp;<br />
	Class.forName(&quot;sun.jdbc.odbc.JdbcOdbcDriver&quot;) ;&nbsp; &nbsp;<br />
	String url=&quot;jdbc:odbc:Driver={MicroSoft Access Driver (*.mdb)};DBQ=&quot;+application.getRealPath(&quot;/Data/ReportDemo.mdb&quot;);&nbsp; &nbsp;<br />
	Connection conn = DriverManager.getConnection(url,&quot;&quot;,&quot;&quot;);&nbsp; &nbsp;<br />
	Statement stmtNew=conn.createStatement() ;&nbsp; &nbsp;<br />
	&nbsp;<br />
	二、JDBC连接MySql方式 <br />
	　　 下面是使用JDBC连接MySql的一个小的教程 <br />
	　　 1、查找驱动程序 <br />
	　　 MySQL目前提供的java驱动程序为Connection/J，可以从MySQL官方网站下载，并找到mysql-connector-java-3.0.15-ga-bin.jar文件，此驱动程序为纯java驱动程序，不需做其他配置。 </p>
<p>	　　 2、动态指定classpath <br />
	　　 如果需要执行时动态指定classpath，就在执行时采用－cp方式。否则将上面的.jar文件加入到classpath环境变量中。 </p>
<p>	　　 3、加载驱动程序 <br />
	Java代码 &nbsp;<br />
	try{&nbsp; &nbsp;<br />
	　 Class.forName(com.mysql.jdbc.Driver);&nbsp; &nbsp;<br />
	　 System.out.println(Success loading Mysql Driver!);&nbsp; &nbsp;<br />
	}catch(Exception e)&nbsp; &nbsp;<br />
	{&nbsp; &nbsp;<br />
	　 System.out.println(Error loading Mysql Driver!);&nbsp; &nbsp;<br />
	　 e.printStackTrace();&nbsp; &nbsp;<br />
	}&nbsp; &nbsp;<br />
	&nbsp;<br />
	　　 4、设置连接的url <br />
	jdbc：mysql：//localhost/databasename[?pa=va][＆pa=va]　<br />
	　 <br />
	三、以下列出了在使用JDBC来连接Oracle数据库时可以使用的一些技巧 <br />
	　　 1、在客户端软件开发中使用Thin驱动程序 <br />
	　　 在开发Java软件方面，Oracle的数据库提供了四种类型的驱动程序，二种用于应用软件、applets、servlets等客户端软件，另外二种用于数据库中的Java存储过程等服务器端软件。在客户机端软件的开发中，我们可以选择OCI驱动程序或Thin驱动程序。OCI驱动程序利用Java本地化接口（JNI），通过Oracle客户端软件与数据库进行通讯。Thin驱动程序是纯Java驱动程序，它直接与数据库进行通讯。为了获得最高的性能，Oracle建议在客户端软件的开发中使用OCI驱动程序，这似乎是正确的。但我建议使用Thin驱动程序，因为通过多次测试发现，在通常情况下，Thin驱动程序的性能都超过了OCI驱动程序。 </p>
<p>	　　 2、关闭自动提交功能，提高系统性能 <br />
	　　 在第一次建立与数据库的连接时，在缺省情况下，连接是在自动提交模式下的。为了获得更好的性能，可以通过调用带布尔值false参数的Connection类的setAutoCommit()方法关闭自动提交功能，如下所示： <br />
	　　 conn.setAutoCommit(false); <br />
	　　 值得注意的是，一旦关闭了自动提交功能，我们就需要通过调用Connection类的commit()和rollback()方法来人工的方式对事务进行管理。 </p>
<p>	　　 3、在动态SQL或有时间限制的命令中使用Statement对象 <br />
	　　 在执行SQL命令时，我们有二种选择：可以使用PreparedStatement对象，也可以使用Statement对象。无论多少次地使用同一个SQL命令，PreparedStatement都只对它解析和编译一次。当使用Statement对象时，每次执行一个SQL命令时，都会对它进行解析和编译。这可能会使你认为，使用PreparedStatement对象比使用Statement对象的速度更快。然而，我进行的测试表明，在客户端软件中，情况并非如此。因此，在有时间限制的SQL操作中，除非成批地处理SQL命令，我们应当考虑使用Statement对象。 </p>
<p>	　　 此外，使用Statement对象也使得编写动态SQL命令更加简单，因为我们可以将字符串连接在一起，建立一个有效的SQL命令。因此，我认为，Statement对象可以使动态SQL命令的创建和执行变得更加简单。 </p>
<p>	　　 4、利用helper函数对动态SQL命令进行格式化 <br />
	　　 在创建使用Statement对象执行的动态SQL命令时，我们需要处理一些格式化方面的问题。例如，如果我们想创建一个将名字O&#39;Reilly插入表中的SQL命令，则必须使用二个相连的&ldquo;&#39;&#39;&rdquo;号替换O&#39;Reilly中的&ldquo;&#39;&rdquo;号。完成这些工作的最好的方法是创建一个完成替换操作的helper方法，然后在连接字符串心服用公式表达一个SQL命令时，使用创建的helper方法。与此类似的是，我们可以让helper方法接受一个Date型的值，然后让它输出基于Oracle的to_date()函数的字符串表达式。 <br />
	　　 5、利用PreparedStatement对象提高数据库的总体效率 <br />
	　　 在使用PreparedStatement对象执行SQL命令时，命令被数据库进行解析和编译，然后被放到命令缓冲区。然后，每当执行同一个PreparedStatement对象时，它就会被再解析一次，但不会被再次编译。在缓冲区中可以发现预编译的命令，并且可以重新使用。在有大量用户的企业级应用软件中，经常会重复执行相同的SQL命令，使用PreparedStatement对象带来的编译次数的减少能够提高数据库的总体性能。如果不是在客户端创建、预备、执行PreparedStatement任务需要的时间长于Statement任务，我会建议在除动态SQL命令之外的所有情况下使用PreparedStatement对象。 </p>
<p>	　　 6、在成批处理重复的插入或更新操作中使用PreparedStatement对象 <br />
	　　 如果成批地处理插入和更新操作，就能够显著地减少它们所需要的时间。Oracle提供的Statement和 CallableStatement并不真正地支持批处理，只有PreparedStatement对象才真正地支持批处理。我们可以使用addBatch()和executeBatch()方法选择标准的JDBC批处理，或者通过利用PreparedStatement对象的setExecuteBatch()方法和标准的executeUpdate()方法选择速度更快的Oracle专有的方法。要使用Oracle专有的批处理机制，可以以如下所示的方式调用setExecuteBatch()：<br />
	PreparedStatement pstmt3D null; <br />
	try { <br />
	　 ((OraclePreparedStatement)pstmt).setExecuteBatch(30); <br />
	　 ... <br />
	　 pstmt.executeUpdate(); <br />
	} </p>
<p>	　　 调用setExecuteBatch()时指定的值是一个上限，当达到该值时，就会自动地引发SQL命令执行，标准的executeUpdate()方法就会被作为批处理送到数据库中。我们可以通过调用PreparedStatement类的sendBatch()方法随时传输批处理任务。 </p>
<p>	　　 7、使用Oracle locator方法插入、更新大对象（LOB） <br />
	　　 Oracle的PreparedStatement类不完全支持BLOB和CLOB等大对象的处理，尤其是Thin驱动程序不支持利用PreparedStatement对象的setObject()和setBinaryStream()方法设置BLOB的值，也不支持利用setCharacterStream()方法设置CLOB的值。只有locator本身中的方法才能够从数据库中获取LOB类型的值。可以使用PreparedStatement对象插入或更新LOB，但需要使用locator才能获取LOB的值。由于存在这二个问题，因此，我建议使用locator的方法来插入、更新或获取LOB的值。 </p>
<p>	　　 8、使用SQL92语法调用存储过程 <br />
	　　 在调用存储过程时，我们可以使用SQL92或Oracle PL/SQL，由于使用Oracle PL/SQL并没有什么实际的好处，而且会给以后维护你的应用程序的开发人员带来麻烦，因此，我建议在调用存储过程时使用SQL92。 </p>
<p>	　　 9、使用Object SQL将对象模式转移到数据库中 <br />
	　　 既然可以将Oracle的数据库作为一种面向对象的数据库来使用，就可以考虑将应用程序中的面向对象模式转到数据库中。目前的方法是创建Java bean作为伪装的数据库对象，将它们的属性映射到关系表中，然后在这些bean中添加方法。尽管这样作在Java中没有什么问题，但由于操作都是在数据库之外进行的，因此其他访问数据库的应用软件无法利用对象模式。如果利用Oracle的面向对象的技术，可以通过创建一个新的数据库对象类型在数据库中模仿其数据和操作，然后使用JPublisher等工具生成自己的Java bean类。如果使用这种方式，不但Java应用程序可以使用应用软件的对象模式，其他需要共享你的应用中的数据和操作的应用软件也可以使用应用软件中的对象模式。 </p>
<p>	　　 10、利用SQL完成数据库内的操作 <br />
	　　 我要向大家介绍的最重要的经验是充分利用SQL的面向集合的方法来解决数据库处理需求，而不是使用Java等过程化的编程语言。 </p>
<p>	　　 如果编程人员要在一个表中查找许多行，结果中的每个行都会查找其他表中的数据，最后，编程人员创建了独立的UPDATE命令来成批地更新第一个表中的数据。与此类似的任务可以通过在set子句中使用多列子查询而在一个UPDATE命令中完成。当能够在单一的SQL命令中完成任务，何必要让数据在网上流来流去的？我建议用户认真学习如何最大限度地发挥SQL的功能。</p>
<div style="clear: both; margin: 10px 0pt; border: 1px dashed rgb(153, 153, 153); font-size: 12px; padding: 5px 10px;">
<li>本文链接地址：<a href="https://www.dbainfo.net/java-connect-url-for-oracle-db2-sql-sybase-informix-mysql-pgsql.htm">https://www.dbainfo.net/java-connect-url-for-oracle-db2-sql-sybase-informix-mysql-pgsql.htm</a>；</li>
<li>本文为dbainfo个人原创，请在尊重作者劳动成果的前提下进行转载；</li>
<li>转载务必注明原始出处 : <a href="https://www.dbainfo.net/">Sybase数据库技术，数据库恢复专家</a>；</li>
<li>对《<a href="https://www.dbainfo.net/java-connect-url-for-oracle-db2-sql-sybase-informix-mysql-pgsql.htm">java连接数据库Oracle,DB2,SQL Server,Sybase,Informix,MySQL,PostgreSQL</a>》有何疑问或见解，请在本文下方发表；</li>
<li>对网站还有其他问题或建议，请提交在<a href="https://www.dbainfo.net/messages" target="_blank">留言板</a>，谢谢！</li>
</div>
<h2  class="related_post_title">相关文章</h2><ul class="related_post"><li>2011-10-14 -- <a href="https://www.dbainfo.net/history-of-common-databases.htm" title="各数据库的发展历史">各数据库的发展历史</a> (0)</li><li>2019-04-12 -- <a href="https://www.dbainfo.net/sybase-ase-asa-recovery-service.htm" title="Sybase ASE及SQL Anywhere数据库修复专家">Sybase ASE及SQL Anywhere数据库修复专家</a> (0)</li><li>2019-04-11 -- <a href="https://www.dbainfo.net/sql-server-recovery-service.htm" title="SQL Server 数据库修复专家SQLRescue">SQL Server 数据库修复专家SQLRescue</a> (0)</li><li>2013-09-16 -- <a href="https://www.dbainfo.net/select-random-rows-from-table.htm" title="ASE从表中随机选择数据的三种方法">ASE从表中随机选择数据的三种方法</a> (0)</li><li>2013-09-08 -- <a href="https://www.dbainfo.net/get-current-running-sql.htm" title="查看ASE v15正在执行的SQL语句内容">查看ASE v15正在执行的SQL语句内容</a> (0)</li><li>2013-05-23 -- <a href="https://www.dbainfo.net/rename-sybase-ase-servername.htm" title="修改ASE的服务器名称">修改ASE的服务器名称</a> (0)</li><li>2012-06-22 -- <a href="https://www.dbainfo.net/introduce-sql-anywhere-recovery-tool-readasadb.htm" title="Sybase SQL Anywhere(ASA)数据库非常规恢复工具">Sybase SQL Anywhere(ASA)数据库非常规恢复工具</a> (0)</li><li>2012-04-11 -- <a href="https://www.dbainfo.net/ase-alter-table-modify-column-default-value.htm" title="ASE修改列的默认值属性">ASE修改列的默认值属性</a> (0)</li><li>2012-03-21 -- <a href="https://www.dbainfo.net/an-sybase-method-to-remove-same-records.htm" title="Sybase去除重复数据的一种方法">Sybase去除重复数据的一种方法</a> (0)</li><li>2011-12-01 -- <a href="https://www.dbainfo.net/oracle11g-tns-12537-and-ora-609-troubleshooting.htm" title="oracle11g报TNS-12537和ORA-609问题的解决">oracle11g报TNS-12537和ORA-609问题的解决</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>https://www.dbainfo.net/java-connect-url-for-oracle-db2-sql-sybase-informix-mysql-pgsql.htm/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
