[学习笔记]

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. Java 基础:抽象类与接口

    1.什么是抽象 当父类的某些方法不确定时,可以用abstract关键字来修饰该方法[抽象方法],用abstract来修饰该类[抽象类]. 我们都知道,父类是将子类所共同拥有的属性和方法进行抽取,这些属 ...

  2. crontab 定时访问指定url,定时脚本

    一.contab格式说明 二.定时访问url: 1.连接远程主机,连接成功后,输入命令  crontab -e : 2.参照VI编辑器.按字母 i 进入编辑模式,输入需要执行的脚本:(在这里之前要检查 ...

  3. PKUWC2020 游记

    因为CSP-S挂的并不厉害,蜜汁来到了PKU,所以有了这篇游记. DAY 0 上午在机房颓废,中途还整了一个出校证. 九点多,两个THU的大神去拿笔记本和手机颓废了,不久被两个教练拉着和kx跑了出去. ...

  4. mysql删除大表

    在mysql中遇到一个大表,大概有17G左右,在对这个表进行查询.修改时均遇到了很大的困难,于是想着删除这张表.通常的删除操作可以通过delete.drop.truncate操作,试了这三个命令,但是 ...

  5. game-hacking

    https://github.com/dsasmblr/game-hacking Cheat Engine Hacking memory Cheat engine have a feature cal ...

  6. Java实现视频网站的视频上传、视频转码、及视频播放功能(ffmpeg)

    视频网站中提供的在线视频播放功能,播放的都是FLV格式的文件,它是Flash动画文件,可通过Flash制作的播放器来播放该文件.项目中用制作的player.swf播放器. 多媒体视频处理工具FFmpe ...

  7. Java项目登录报Session Error

    在web.xml文件添加下面红色代码即可,注意:添加代码后,格式化一下代码. <servlet>        <servlet-name>dwr-invoker</se ...

  8. Centos7迁移fastdfs文件系统

    系统从一个地方迁移到另一个地方,数据保持不变,但是ip地址和网络情况不一样了,最困难的是要迁移的那个地方还么有互联网,这TM就坑了,所以想到将FastDFS存储的目录整体拷贝过去,这个方法简单粗暴,这 ...

  9. linux内核中i2c驱动中slave模式接口的调用

    1. 关注unreg_slave接口 1.1 这个接口在哪里被调用呢? 在drivers/i2c/i2c-core-slave.c中 int i2c_slave_unregister(struct i ...

  10. Python3基础 运算 加减乘除、取余数

             Python : 3.7.3          OS : Ubuntu 18.04.2 LTS         IDE : pycharm-community-2019.1.3    ...