JTDS的使用
2020-03-22 00:20

  JTDS不需要特别的安装,只需要把JAR文件放在classpath路径中就可以了。 

    显示表:

    public static void main(String[] args) {
        Connection conn = ByConnection.getConnection();
        try {
            Statement st=conn.createStatement();
            st.execute("insert into dept(name) values('5555')");
            st.close();
            conn.close();
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

public class test01 {

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

    create database Geek99DB;

 

  }finally {图片 1图片 2

    }

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

下载与安装

//建立SQL语句对象,执行查询
  String sql="select id,name,email from CustomerTbl";
  try {
   Statement stmt =conn.createStatement();
   ResultSet rs=stmt.executeQuery(sql);

public class ByConnection {
    public static Connection getConnection() {
        String dbDriver = "net.sourceforge.jtds.jdbc.Driver";
        String strConnection = "jdbc:jtds:sqlserver://localhost:1433/Test";
        String user = "sa";
        String password = "1";
        Connection conn = null;
        try {
            Class.forName(dbDriver);
            conn = DriverManager.getConnection(strConnection, user, password);
        } catch (ClassNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return conn;

}

JTDS是一个开放源代码的100%纯Java的,用于JDBC 3.0驱动Microsoft SQL Server (6.5 ,7 ,2000和2005版本)和Sybase(10 ,11 ,12 ,15 版本)的驱动程序 。 JTDS是基于freetds的,并且是目前最快的生产准备JDBC驱动程序为SQL Server和Sybase 。 JTDS完全与JDBC 3.0兼容,支持只向前的,和可滚动/可更新的结果集(ResultSets)中并行(完全独立)语句,并且可实施所有databasemetadata和resultsetmetadata方法。 

    create table CustomerTab(id int primary key auto_increment,name varcahr(20),email varchar(20));

用jtds连接SQL2000的方法

然后新建一个class文件,代码如下:

  官方网站下载地址: 

 

MicrosoftInternetExplorer402DocumentNotSpecified7.8Normal0

 }

}

//加载JDBC驱动
  Connection conn=null;
  try {
   Class.forName("com.mysql.jdbc.Driver");
  } catch (ClassNotFoundException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }

  官方网站首页: 

//关闭数据连接
   if(conn!=null){
    try {
     conn.close();
    } catch (SQLException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
    }
   }
  }

    insert into CustomerTbl(name,email)values('tam','123@qq.com');

上一篇:结构体详解 下一篇:没有了