java当中JDBC当中请给出一个sql server的helloworld例子
[学习笔记]
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例子的更多相关文章
- java当中JDBC当中请给出一个sql server的stored procedure例子
3.sql server的stored procedure例子: import java.sql.*;public class StoredProc0 {public static void main ...
- java当中JDBC当中请给出一个sql server的dataSource的helloworld例子
[学习笔记] 4. sql server的dataSource的helloworld: import java.sql.*;import javax.sql.*;import net.sourcef ...
- 请给出一个Scala RDD的HelloWorld例子
[学习笔记]package comimport org.apache.spark.rdd.RDDimport org.apache.spark.SparkConfimport org.apache.s ...
- java当中JDBC当中请给出一个Oracle DataSource and SingleTon例子
[学习笔记] 6.Oracle DataSource and SingleTon: import oracle.jdbc.pool.OracleDataSource;import java.sql.C ...
- java当中JDBC当中请给出一个SQLServer DataSource and SingleTon例子
[学习笔记] 5.SQLServer DataSource and SingleTon: import net.sourceforge.jtds.jdbcx.*;import java.sql.*;i ...
- 已知一个函数rand7()能够生成1-7的随机数,请给出一个函数rand10(),该函数能够生成1-10的随机数。
题目: 已知一个函数rand7()能够生成1-7的随机数,请给出一个函数,该函数能够生成1-10的随机数. 思路: 假如已知一个函数能够生成1-49的随机数,那么如何以此生成1-10的随机数呢? 解法 ...
- 请写出一个超链接,点击链接后可以向zhangsan@d-heaven.com发送电子邮件。
请写出一个超链接,点击链接后可以向zhangsan@d-heaven.com发送电子邮件. <a href=”mailto: zhangsan@d-heaven.com”>发邮件</ ...
- 使用java以及jdbc不使用第三方库执行sql文件脚本
使用java以及jdbc不使用第三方库执行sql文件脚本 2017年02月15日 15:51:45 阅读数:660 使用java执行sql脚本的方法 解析sql脚本,删除不必要的注释和空行 将语句按分 ...
- 如何使用OPENQUERY访问另一个SQL Server
原文:如何使用OPENQUERY访问另一个SQL Server 在项目中,经常会遇到一个数据库访问另一个数据库,[CNVFERPDB]为服务器名,[CE3]为库名 SELECT Dtl.* FROM ...
随机推荐
- 7、vueJs基础知识07
UI组件库 element-ui和mint-ui 其实都是借鉴了bootstrap bootstrap: 由twitter 开源 简洁.大方 官网文档https://www.bootcss.com/ ...
- webpack4-用之初体验
众所周知,webpack进入第4个大版本已经有2个月的时间了,而且webpack团队升级更新的速度也是非常的惊人 在写下如下内容的时候webpack已经出到了4.6的版本了,剑指5.0应该是指日可待了 ...
- 微信JS-SDK分享功能的.Net实现代码
JS-SDK接口是什么? 为了方便开发者实现微信内的网页(基于微信浏览器访问的网页)功能,比如拍照.选图.语音.位置等手机系统的能力,并方便开发者直接使用微信分享.扫一扫等微信特有的能力,微信推出了J ...
- 【转】自动化框架中引入ExtentReport美化报告
本文链接:https://blog.csdn.net/qq_30353203/article/details/82023922一.先引入三个依赖包 <dependency> <gro ...
- MiniUI增删改查操作及确认按钮
原文:https://blog.csdn.net/codezdx/article/details/81565043 1.动态创建列:尽量不要直接在html文件里创建列,动态设置在js文件里方面添加.修 ...
- springMVC Controller 参数映射
springMVC 对参数为null或参数不为null的处理 - 小浩子的博客 - CSDN博客https://blog.csdn.net/change_on/article/details/7664 ...
- 小D课堂 - 零基础入门SpringBoot2.X到实战_第7节 SpringBoot常用Starter介绍和整合模板引擎Freemaker、thymeleaf_28..SpringBoot Starter讲解
笔记 1.SpringBoot Starter讲解 简介:介绍什么是SpringBoot Starter和主要作用 1.官网地址:https://docs.spring.io/spring-b ...
- git-scm教程摘要
Git 有三种状态 已提交(committed).已修改(modified)和已暂存(staged) 已提交表示数据已经安全的保存在本地数据库中. 已修改表示修改了文件,但还没保存到数据库中. 已暂存 ...
- 教孩子学编程 Python
教孩子学编程 Python 目录 第1 章 Python 基础:认识环境 111 认识Python 312 用Python 编写程序 513 运行Python 程序 514 本章小结 615 编程 ...
- Python - Django - ORM 常用的字段属性
字段参数: null:用于表示某个字段可以为空 unique:如果设置为 unique=True,则该字段在此表中必须是唯一的 db_index:如果 db_index=True,则代表着为此字段设置 ...