Java Sky of Zhao
受挫一次,对生活的理解加深一层;失误一次对人生的感悟增添一阶;不幸一次,对世界的认识成熟一级;磨难一次,对成功的内涵透彻一遍!
posts - 5,comments - 4,trackbacks - 0
MySQL中判断表是否存在:
1. SHOW   TABLES   LIKE   '%tb_bp_d_case%';  

2. select `TABLE_NAME` from `INFORMATION_SCHEMA`.`TABLES` where `TABLE_SCHEMA`='dbname' and `TABLE_NAME`='tablename' ;

3. 如果表不存在就建立这个表,那么可以直接用 create table if not exists tablename 这样的指令来建立,不需要先去查询表是否存在。

4. 从模板表创建表:create table if not exists like old_table_name;

文章出处:DIY部落(http://www.diybl.com/course/7_databases/mysql/Mysqljs/20090313/161045.html)
posted @ 2010-01-08 20:22 SINOJAVA 阅读(2136) | 评论 (0)编辑 收藏
 

[ 原创 ] JDBC 如何连接 SQL SERVER 2000 的默认实例和命名实例

 

引用请注明出处 :http//www.blogjava.net/SINOJAVA

 

( ) 下载 Microsoft SQL Server 2000 Service Pack 3a 并安装
http://www.microsoft.com/downloads/details.aspx?FamilyId=90DCD52C-0488-4E46-AFBF-ACACE5369FA3&displaylang=zh-cn

 

( ) 下载并安装 SQL SERVER 2000 JDBC 驱动 ( SQL Server 2000 Driver for JDBC Service Pack 3 )

http://www.microsoft.com/downloads/details.aspx?FamilyId=07287B11-0502-461A-B138-2AA54BFDC03A&displaylang=en

 

( ) 配置 JDBC 驱动 classpath 环境变量 :

方法 1:

 

填加 :

C:\Program Files\Microsoft SQL Server 2000 Driver for JDBC\lib\msbase.jar;

C:\Program Files\Microsoft SQL Server 2000 Driver for JDBC\lib\mssqlserver.jar;

C:\Program Files\Microsoft SQL Server 2000 Driver for JDBC\lib\msutil.jar;

 

: C:\Program Files\Microsoft SQL Server 2000 Driver for JDBC\ 为我 JDBC 得安装路径

 

方法 2:

 

mssqlserver.jar; msutil.jar; msbase.jar 拷贝到 JDK lib 目录下 , 然后设置 classpath

 

D:\Java\jdk1.5.0_05\lib\sqlserver\msutil.jar;

D:\Java\jdk1.5.0_05\lib\sqlserver\msbase.jar;

D:\Java\jdk1.5.0_05\lib\sqlserver\mssqlserver.jar;

 

( ) 创建连接数据库默认实例得连接代码 :

 

import java.sql.*;

public class ConSqlserver {

    

     Connection con=null;

     //Statement st=null;

     //ResultSet re=null;

    

     public ConSqlserver()

     {

            try

            {

                String driver="com.microsoft.jdbc.sqlserver.SqlServerDriver";

                String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=Northwind";

                Class.forName(driver).newInstance();

                con =DriverManager.getConnection(url,"sa","zhaopf");

                System.out.println(" 连接成功 !");

                con.close();

           

            }

            catch(Exception e)

            {

                   e.printStackTrace();

            }

           

           

     }

 

       public static void main(String[] args)

     {

            // TODO 自动生成方法存根

            ConSqlserver con=new ConSqlserver();

           

 

     }

 

}

 

( ) 创建连接数据库命名实例的连接代码 ( 实例名为 SINOIT\SINOSERVER) L

 

import java.sql.*;

public class ConSqlserverppp {

    

     Connection con=null;

     //Statement st=null;

     //ResultSet re=null;

    

     public ConSqlserverppp()

     {

            try

            {

                //String driver="com.microsoft.jdbc.sqlserver.SqlServerDriver";

                String url="jdbc:microsoft:sqlserver://SINOIT\\SINOSERVER;DatabaseName=Northwind";

               

                Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();

                  

                //Class.forName(driver);//.newInstance();

                con =DriverManager.getConnection(url,"sa","zse");

                //st=con.createStatement();

                System.out.println(" 连接成功 !");

                con.close();

           

            }

            catch(Exception e)

            {

                   e.printStackTrace();

            }

           

           

     }

 

     public static void main(String[] args)

     {

           

            ConSqlserverppp con=new ConSqlserverppp();

     }

 

}

posted @ 2006-04-10 07:24 SINOJAVA 阅读(2644) | 评论 (1)编辑 收藏
我的blog开业了,欢迎大家前来支持,谢谢!!
posted @ 2006-04-08 07:58 SINOJAVA 阅读(644) | 评论 (2)编辑 收藏
仅列出标题