﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>IT博客-stormbigboy-文章分类-Database</title><link>http://www.cnitblog.com/strombigboy/category/8024.html</link><description>【Amos】工作室</description><language>zh-cn</language><lastBuildDate>Wed, 28 Sep 2011 10:44:33 GMT</lastBuildDate><pubDate>Wed, 28 Sep 2011 10:44:33 GMT</pubDate><ttl>60</ttl><item><title>关于JAVA 连接各种主流数据库的方法总结</title><link>http://www.cnitblog.com/strombigboy/articles/54374.html</link><dc:creator>流浪汉</dc:creator><author>流浪汉</author><pubDate>Mon, 09 Feb 2009 04:05:00 GMT</pubDate><guid>http://www.cnitblog.com/strombigboy/articles/54374.html</guid><wfw:comment>http://www.cnitblog.com/strombigboy/comments/54374.html</wfw:comment><comments>http://www.cnitblog.com/strombigboy/articles/54374.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/strombigboy/comments/commentRss/54374.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/strombigboy/services/trackbacks/54374.html</trackback:ping><description><![CDATA[关于JAVA 连接数据库，有很多初学者都感觉到很难，其实，掌握了它的驱动模型可以了，为了便于查找，下面给出一个速查表，JAVA 连接各种数据库。　<br><br><br>简述：<br><br>　Java数据库连接（JDBC）由一组用 Java 编程语言编写的类和接口组成。JDBC 为工具/数据库开发人员提供了一个标准的 API，使他们能够用纯Java API 来编写数据库应用程序。然而各个开发商的接口并不完全相同，所以开发环境的变化会带来一定的配置变化。<br>　　<strong>一、连接各种数据库方式速查表</strong><br><br>　　下面罗列了各种数据库使用JDBC连接的方式，可以作为一个手册使用。 <br><br>　　1、Oracle8/8i/9i数据库（thin模式） <br><br>
<table borderColor=#ffcc66 width="90%" align=center bgColor=#dadacf border=1>
    <tbody>
        <tr>
            <td>Class.forName("oracle.jdbc.driver.OracleDriver").newInstance(); <br>String url="jdbc:oracle:thin:@localhost:1521:orcl"; //orcl为数据库的SID <br>String user="test"; <br>String password="test"; <br>Connection conn= DriverManager.getConnection(url,user,password); </td>
        </tr>
    </tbody>
</table>
<br>　　2、DB2数据库 <br><br>
<table borderColor=#ffcc66 width="90%" align=center bgColor=#dadacf border=1>
    <tbody>
        <tr>
            <td>Class.forName("com.ibm.db2.jdbc.app.DB2Driver ").newInstance(); <br>String url="jdbc:db2://localhost:5000/sample"; //sample为你的数据库名 <br>String user="admin"; <br>String password=""; <br>Connection conn= DriverManager.getConnection(url,user,password); </td>
        </tr>
    </tbody>
</table>
<br>　　3、Sql Server7.0/2000数据库 <br><br>
<table borderColor=#ffcc66 width="90%" align=center bgColor=#dadacf border=1>
    <tbody>
        <tr>
            <td>Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance(); <br>String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=mydb"; <br>//mydb为数据库 <br>String user="sa"; <br>String password=""; <br>Connection conn= DriverManager.getConnection(url,user,password); </td>
        </tr>
    </tbody>
</table>
<br>　　4、Sybase数据库 <br><br>
<table borderColor=#ffcc66 width="90%" align=center bgColor=#dadacf border=1>
    <tbody>
        <tr>
            <td>Class.forName("com.sybase.jdbc.SybDriver").newInstance(); <br>String url =" jdbc:sybase:Tds:localhost:5007/myDB";//myDB为你的数据库名 <br>Properties sysProps = System.getProperties(); <br>SysProps.put("user","userid"); <br>SysProps.put("password","user_password"); <br>Connection conn= DriverManager.getConnection(url, SysProps); </td>
        </tr>
    </tbody>
</table>
<br>　　5、Informix数据库 <br><br>
<table borderColor=#ffcc66 width="90%" align=center bgColor=#dadacf border=1>
    <tbody>
        <tr>
            <td>Class.forName("com.informix.jdbc.IfxDriver").newInstance(); <br>String url = "jdbc:informix-sqli://123.45.67.89:1533/myDB:INFORMIXSERVER=myserver; <br>user=testuser;password=testpassword"; //myDB为数据库名 <br>Connection conn= DriverManager.getConnection(url); </td>
        </tr>
    </tbody>
</table>
<br>　　6、MySQL数据库 <br><br>
<table borderColor=#ffcc66 width="90%" align=center bgColor=#dadacf border=1>
    <tbody>
        <tr>
            <td>Class.forName("org.gjt.mm.mysql.Driver").newInstance(); <br>String url ="jdbc:mysql://localhost/myDB?user=soft&amp;password=soft1234&amp;useUnicode=true&amp;characterEncoding=8859_1" <br>//myDB为数据库名 <br>Connection conn= DriverManager.getConnection(url); </td>
        </tr>
    </tbody>
</table>
<br>　　7、PostgreSQL数据库 <br><br>
<table borderColor=#ffcc66 width="90%" align=center bgColor=#dadacf border=1>
    <tbody>
        <tr>
            <td>Class.forName("org.postgresql.Driver").newInstance(); <br>String url ="jdbc:postgresql://localhost/myDB" //myDB为数据库名 <br>String user="myuser"; <br>String password="mypassword"; <br>Connection conn= DriverManager.getConnection(url,user,password); </td>
        </tr>
    </tbody>
</table>
<br>　　8、access数据库直连用ODBC的<br><br>
<table borderColor=#ffcc66 width="90%" align=center bgColor=#dadacf border=1>
    <tbody>
        <tr>
            <td>Class.forName("sun.jdbc.odbc.JdbcOdbcDriver") ;<br>String url="jdbc:odbc:Driver={MicroSoft Access Driver (*.mdb)};DBQ="+application.getRealPath("/Data/ReportDemo.mdb");<br>Connection conn = DriverManager.getConnection(url,"","");<br>Statement stmtNew=conn.createStatement() ;</td>
        </tr>
    </tbody>
</table>
<br>　　<strong>二、JDBC连接MySql方式</strong><br><br>　　下面是使用JDBC连接MySql的一个小的教程 <br><br>　　1、查找驱动程序<br><br>　　MySQL目前提供的java驱动程序为Connection/J，可以从MySQL官方网站下载，并找到mysql-connector-java-3.0.15-ga-bin.jar文件，此驱动程序为纯java驱动程序，不需做其他配置。<br><br>　　2、动态指定classpath<br><br>　　如果需要执行时动态指定classpath，就在执行时采用－cp方式。否则将上面的.jar文件加入到classpath环境变量中。<br><br>　　3、加载驱动程序<br><br>
<table borderColor=#ffcc66 width="90%" align=center bgColor=#dadacf border=1>
    <tbody>
        <tr>
            <td>try{<br>　Class.forName(com.mysql.jdbc.Driver);<br>　System.out.println(Success loading Mysql Driver!);<br>}catch(Exception e)<br>{<br>　System.out.println(Error loading Mysql Driver!);<br>　e.printStackTrace();<br>}</td>
        </tr>
    </tbody>
</table>
<br>　　4、设置连接的url<br><br>
<table borderColor=#ffcc66 width="90%" align=center bgColor=#dadacf border=1>
    <tbody>
        <tr>
            <td>jdbc：mysql：//localhost/databasename[?pa=va][＆pa=va]</td>
        </tr>
    </tbody>
</table>
<br><br>以上的总结。希望对刚学java不久的你有帮助。
<img src ="http://www.cnitblog.com/strombigboy/aggbug/54374.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/strombigboy/" target="_blank">流浪汉</a> 2009-02-09 12:05 <a href="http://www.cnitblog.com/strombigboy/articles/54374.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>将MySQL数据库转换为SQL Server的数据库</title><link>http://www.cnitblog.com/strombigboy/articles/54254.html</link><dc:creator>流浪汉</dc:creator><author>流浪汉</author><pubDate>Wed, 04 Feb 2009 13:11:00 GMT</pubDate><guid>http://www.cnitblog.com/strombigboy/articles/54254.html</guid><wfw:comment>http://www.cnitblog.com/strombigboy/comments/54254.html</wfw:comment><comments>http://www.cnitblog.com/strombigboy/articles/54254.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/strombigboy/comments/commentRss/54254.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/strombigboy/services/trackbacks/54254.html</trackback:ping><description><![CDATA[<p>将MySQL数据库转换为SQL Server的数据库，或者将SQL Server数据库转换为MySQL的数据库,在NT环境下很多时候都会用到。使用MySQL ODBC后就比较好办，可以使用SQL Server7的管理工具，也可以使用MySQL的管理工具，更可以使用其它方的管理工具。这里介绍一个使用SQL7的MMC的方法 ，将SQL Server7的数据转化为MySQL的数据库，将源和目的反之，就可以将MySQL的数据库转化为SQL Server7的数据库。 </p>
<p><br>1.安装MySQL的ODBC接口。 </p>
<p><br>2.建立MySQL的DSN，可以建系统DSN，这里命名testMySQL,填写IP,dababase,用户名口令等项，完成。 </p>
<p><br>3.在SQL7的MMC中，选择要导出的数据库，右键选择All Tasks-&gt;Export Datas。 </p>
<p><br>4.开始DTS Export Wizerd： </p>
<p><br>Choose a Data Source:Microsoft OLE DB Privoder for SQL Server</p>
<p>server:你的SQL Server7数据库的服务器 </p>
<p>是否使用NT认证和用户名口令看你自己的了。最后选择一个Database,如:mynews(你自己要导到MySQL中的数据库)。 </p>
<p><br>5.Choose a Destination:选MySQL： </p>
<p><br>User/System DSN,如果建立过就选择，如果没有建立就新建。 </p>
<p><br>6.Specify Table Copy or Query： </p>
<p><br>Copy table(s) from the source database,从源数据库拷贝表开始 </p>
<p><br>7.Select Source Table： </p>
<p><br>选择要拷贝的表，如果不想仔细调整，就选择全部吧。 </p>
<p><br>8.Run immediately,当然要立即执行，下一步再选完成，就开始转换。 </p>
<p><br>这个转换有时一部分表可能要失败，双击失败的表格，看看什么原因，一般是SQL7的数据类型问题，作一些小的修改就应该可以了。 </p>
<p>本篇文章来源于 IT中国 转载请以链接形式注明出处 网址：<a href="http://www.it86.cc/develop/2008/0312/24232.shtml">http://www.it86.cc/develop/2008/0312/24232.shtml</a></p>
<img src ="http://www.cnitblog.com/strombigboy/aggbug/54254.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/strombigboy/" target="_blank">流浪汉</a> 2009-02-04 21:11 <a href="http://www.cnitblog.com/strombigboy/articles/54254.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>