随笔 - 2, 文章 - 0, 评论 - 0, 引用 - 0
数据加载中……

2010年4月1日

Java 删除文件夹以及文件夹下的子目录与文件

// 删除文件夹以及文件夹下的子目录与文件
private void deleteFile(File file) {
    
if (file.exists()) {
        
if (file.isFile()) {
            file.delete();
        } 
else if (file.isDirectory()) {
            File[] files 
= file.listFiles();
            
for (File f : files) {
                
this.deleteFile(f);
            }

        }
        file.delete();
    } 
else {
        System.out.println(
"所删除的" + file.getAbsolutePath() + "不存在!");
    }
}

posted @ 2010-04-01 09:08 lshy168 阅读(428) | 评论 (0)编辑 收藏

2009年5月20日

Java中的JDBC常用的连接字符串

1Microsoft SQLServer(http://www.microsoft.com)

        (SqlServer 2000)
            Class.forName( 
"com.microsoft.jdbc.sqlserver.SQLServerDriver" );
            cn 
= DriverManager.getConnection( "jdbc:microsoft:sqlserver://localhost:1433;databaseName=pubs", sUsr, sPwd );

        (SqlServer 2005)

            Class.forName( 
"com.microsoft.sqlserver.jdbc.SQLServerDriver" );
            cn 
= DriverManager.getConnection( "jdbc:sqlserver://localhost:1433;databaseName=pubs", sUsr, sPwd );

2Oracle(http://www.oracle.com/ip/deploy/database/oracle9i/)classes12.zip
        Class.forName( "oracle.jdbc.driver.OracleDriver" );
        cn 
= DriverManager.getConnection( "jdbc:oracle:thin:@MyDbComputerNameOrIP:1521:ORCL", sUsr, sPwd );
        
3MySQL(http://www.mysql.com)mm.mysql-2.0.2-bin.jar
        Class.forName( "org.gjt.mm.mysql.Driver" );
        cn 
= DriverManager.getConnection( "jdbc:mysql://MyDbComputerNameOrIP:3306/myDatabaseName", sUsr, sPwd );

4PostgreSQL(http://www.de.postgresql.org)pgjdbc2.jar
        Class.forName( "org.postgresql.Driver" );
        cn 
= DriverManager.getConnection( "jdbc:postgresql://MyDbComputerNameOrIP/myDatabaseName", sUsr, sPwd );

5Sybase(http://jtds.sourceforge.net)jconn2.jar
        Class.forName( "com.sybase.jdbc2.jdbc.SybDriver" );
        cn 
= DriverManager.getConnection( "jdbc:sybase:Tds:MyDbComputerNameOrIP:2638", sUsr, sPwd );
        
//(Default-Username/Password: "dba"/"sql")

6Microsoft SQLServer(http://jtds.sourceforge.net)
        Class.forName( "net.sourceforge.jtds.jdbc.Driver" );
        cn 
= DriverManager.getConnection( "jdbc:jtds:sqlserver://MyDbComputerNameOrIP:1433/master", sUsr, sPwd );

7ODBC
        Class.forName(
"sun.jdbc.odbc.JdbcOdbcDriver");
        Connection cn 
= DriverManager.getConnection( "jdbc:odbc:" + sDsn, sUsr, sPwd );

8.DB2(新添加)
        Class.forName(
"com.ibm.db2.jdbc.net.DB2Driver");
        String url
="jdbc:db2://192.9.200.108:6789/SAMPLE"
        cn 
= DriverManager.getConnection( url, sUsr, sPwd );

9.Microsoft SQL Server series (6.57.x and 2000) and Sybase 10

        JDBC Name: jTDS
        URL: http:
//jtds.sourceforge.net/
        Version: 0.5.1
        Download URL: http:
//sourceforge.net/project/showfiles.php?group_id=33291

        语法:
        Class.forName(
"net.sourceforge.jtds.jdbc.Driver ");
        Connection con 
= DriverManager.getConnection("jdbc:jtds:sqlserver://host:port/database","user","password");
        or
        Connection con 
= DriverManager.getConnection("jdbc:jtds:sybase://host:port/database","user","password");

10.Postgresql
        JDBC Name: PostgreSQL JDBC
        URL: http:
//jdbc.postgresql.org/
        Version: 7.3.3 build 110
        Download URL: http:
//jdbc.postgresql.org/download.html
        语法:
        Class.forName(
"org.postgresql.Driver"); 
        Connection con
=DriverManager.getConnection("jdbc:postgresql://host:port/database","user","password");

11.IBM AS400主机在用的JDBC语法
        有装V4R4以上版本的Client Access Express
        可以在C:\Program Files\IBM\Client Access\jt400\lib
        找到 driver 档案 jt400.zip,并更改扩展名成为 jt400.jar
        语法:
        java.sql.DriverManager.registerDriver (
new com.ibm.as400.access.AS400JDBCDriver ());
        Class.forName(
"com.ibm.as400.access.AS400JDBCConnection");
        con 
= DriverManager.getConnection("jdbc:as400://IP","user","password");

12.informix
        Class.forName(
"com.informix.jdbc.IfxDriver").newInstance(); 
        String url 
= 
        
"jdbc:informix-sqli://123.45.67.89:1533/testDB:INFORMIXSERVER=myserver; 
        user=testuser;password=testpassword";
        Lib:jdbcdrv.zip<br><br>Class.forName( "com.sybase.jdbc.SybDriver" )
        url
="jdbc:sybase:Tds:127.0.0.1:2638/asademo";
        SybConnection connection
= (SybConnection)DriverManager.getConnection(url,"dba","sql");

13.SAP DB
        Class.forName (
"com.sap.dbtech.jdbc.DriverSapDB");
        java.sql.Connection connection 
= java.sql.DriverManager.getConnection ( "jdbc:sapdb://" + host + "/" + database_name,user_name, password)
        
        
14.InterBase
        String url 
= "jdbc:interbase://localhost/e:/testbed/database/employee.gdb";
        Class.forName(
"interbase.interclient.Driver");
        
//Driver d = new interbase.interclient.Driver (); /* this will also work if you do not want the line above */
        Connection conn = DriverManager.getConnection( url, "sysdba""masterkey" );

15.HSqlDB
        url:     http:
//hsqldb.sourceforge.net/
        driver:  org.hsqldb.jdbcDriver
        连接方式有4种,分别为:
        con
-str(内存): jdbc:hsqldb.
        con
-str(本地): jdbc:hsqldb:/path/to/the/db/dir
        con
-str(http): jdbc:hsqldb:http://dbsrv
        con-str(hsql): jdbc:hsqldb:hsql://dbsrv

posted @ 2009-05-20 12:58 lshy168 阅读(2230) | 评论 (0)编辑 收藏