[学习笔记]

1.sql server的helloworld例子:

import java.sql.*;

public class JdbcHelloSqlServer {
  public static void main(String[] args) {
    String dbUrl= "jdbc:jtds:sqlserver://localhost:1433/Northwind";String user = "sa";String password = "1234";
//    String   dbUrl="jdbc:mysql://localhost:3306/test"; String user = "root";String password = "1234";
    String createString;
    Statement stmt;
    createString = "select * from orders";
    try {
      /*this method attempts to locate, load,
       and link the class or interface. The specified class loader is
       used to load the class or interface. If the parameter loader is
       null, the class is loaded through the bootstrap class loader.
       about soundBlaster driver?when you talk to the microphone, it can
        record into the computer and save as a file. your sound is
       transfered into 01 signal and save as a file. all these are done by driver.
       the same thing,  using DB? you also need driver.
       */
       Class.forName("net.sourceforge.jtds.jdbc.Driver");
//       Class.forName("com.mysql.jdbc.Driver");
      /*      When the method
       getConnection is called, the DriverManager will attempt to
       locate a suitable driver from amongst those loaded at initialization
       */
      Connection con = DriverManager.getConnection(dbUrl, user, password);
      System.out.println("Connection is ok");
      /* Statement object is a workspace to create SQL queries, execute them, and retrieve any results that are returned.
 tube has track,vehicle is on the track for coal.  vehicle is only suitable for  this track , not for any other track.
       */
      stmt = con.createStatement();
// stmt.execute(createString);
      /* Resultset object contains the table produced by the SQL query
       */
      ResultSet rs = stmt.executeQuery(createString);
      System.out.println("qixybefore");
      //获得元数据
      //获得元数据
      ResultSetMetaData meta = rs.getMetaData();
      for (int i = 1; i <= meta.getColumnCount(); i++) {
        if (meta.getColumnType(i) == java.sql.Types.INTEGER) { // if it is CHAR
          System.out.println("Types.INTEGER is " +i +" " + meta.getColumnName(i)); // display the name
        }

System.out.println(meta.getColumnName(i)); //字段名称
      }
      System.out.println("qixylater");
/*boolean next()  throws SQLException  Moves the cursor down one row from its current position. A ResultSet cursor is initially
 positioned before the first row; the first call to the method next makes the first row the current row; the second call makes
 the second row the current row, and so on.  Returns:true if the new current row is valid; false if there are no more rows */
      while (rs.next()) {
文章转载自原文:https://blog.csdn.net/qq_44594249/article/details/100764762

java当中JDBC当中请给出一个sql server的helloworld例子的更多相关文章

  1. java当中JDBC当中请给出一个sql server的stored procedure例子

    3.sql server的stored procedure例子: import java.sql.*;public class StoredProc0 {public static void main ...

  2. java当中JDBC当中请给出一个sql server的dataSource的helloworld例子

     [学习笔记] 4. sql server的dataSource的helloworld: import java.sql.*;import javax.sql.*;import net.sourcef ...

  3. 请给出一个Scala RDD的HelloWorld例子

    [学习笔记]package comimport org.apache.spark.rdd.RDDimport org.apache.spark.SparkConfimport org.apache.s ...

  4. java当中JDBC当中请给出一个Oracle DataSource and SingleTon例子

    [学习笔记] 6.Oracle DataSource and SingleTon: import oracle.jdbc.pool.OracleDataSource;import java.sql.C ...

  5. java当中JDBC当中请给出一个SQLServer DataSource and SingleTon例子

    [学习笔记] 5.SQLServer DataSource and SingleTon: import net.sourceforge.jtds.jdbcx.*;import java.sql.*;i ...

  6. 已知一个函数rand7()能够生成1-7的随机数,请给出一个函数rand10(),该函数能够生成1-10的随机数。

    题目: 已知一个函数rand7()能够生成1-7的随机数,请给出一个函数,该函数能够生成1-10的随机数. 思路: 假如已知一个函数能够生成1-49的随机数,那么如何以此生成1-10的随机数呢? 解法 ...

  7. 请写出一个超链接,点击链接后可以向zhangsan@d-heaven.com发送电子邮件。

    请写出一个超链接,点击链接后可以向zhangsan@d-heaven.com发送电子邮件. <a href=”mailto: zhangsan@d-heaven.com”>发邮件</ ...

  8. 使用java以及jdbc不使用第三方库执行sql文件脚本

    使用java以及jdbc不使用第三方库执行sql文件脚本 2017年02月15日 15:51:45 阅读数:660 使用java执行sql脚本的方法 解析sql脚本,删除不必要的注释和空行 将语句按分 ...

  9. 如何使用OPENQUERY访问另一个SQL Server

    原文:如何使用OPENQUERY访问另一个SQL Server 在项目中,经常会遇到一个数据库访问另一个数据库,[CNVFERPDB]为服务器名,[CE3]为库名 SELECT Dtl.* FROM ...

随机推荐

  1. vue后台_纯前端实现excel导出/csv导出

    之前的文件下载功能一般是由前后端配合实现,由于项目需要,纯前端实现了一把excel的导出功能: 一.excel导出 1.安装依赖库 xlsx:这是一个功能强大的excel处理库,但是上手难度也很大,还 ...

  2. git图形化统计工具 - windows下gitstats的安装和使用

    gitstats 是一款git历史统计工具,可以生成定量的统计数据,并以html图表的形式展示.统计文件包括文件数量.代码量.提交量.作者信息.每天活跃度.每周活跃度.每月活跃度以及提交数排名等等,信 ...

  3. Mysql sql_mode设置 timestamp default 0000-00-00 00:00:00 创建表失败处理

    往数据库里创建新表的时候报错: [Err] 1067 - Invalid default value for 'updateTime' DROP TABLE IF EXISTS `passwd_res ...

  4. Web Worker 使用教程【转】

    原文:http://www.ruanyifeng.com/blog/2018/07/web-worker.html 一.概述 JavaScript 语言采用的是单线程模型,也就是说,所有任务只能在一个 ...

  5. sysfs 控制gpio

    按照下面的命令点亮及熄灭LED pi@raspberrypi:/sys/class/gpio $echo 26 > exportpi@raspberrypi:/sys/class/gpio $ ...

  6. VS2019,打开项目之后显示:System.NullReferenceException: 未将对象引用设置到对象的实例

    关闭项目,删除项目文件夹下的隐藏文件夹.vs和bin/obj文件夹

  7. 004-行为型-05-职责链模式(Chain of Responsibility)

    一.概述 为请求创建一个接收此次请求对象的链 该模式构造一系列分别担当不同的职责的类的对象来共同完成一个任务,这些类的对象之间像链条一样紧密相连,所以被称作职责链模式. 在这种模式中,通常每个接收者都 ...

  8. Eclipse安装中文简体语言包

    原文地址:https://blog.csdn.net/qq_41101213/article/details/84405452 方法一:1. 下载中文语言包: 1.1 打开网址:http://www. ...

  9. 泡泡一分钟:eRTIS - A Fully Embedded Real Time 3D Imaging Sonar Sensor for Robotic Applications

    eRTIS - A Fully Embedded Real Time 3D Imaging Sonar Sensor for Robotic Applications eRTIS  - 用于机器人应用 ...

  10. Spring cloud微服务安全实战-6-8sentinel限流实战

    阿里2018年开源的. 简单来说就是干三件事,最终的结果就是保证你的服务可用,不会崩掉.保证服务高可用. 流控 先从最简单的场景来入手. 1.引用一个依赖, 2,声明一个资源. 3.声明一个规则 注意 ...