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 ...
随机推荐
- hdoj 1010-Tempter of the Bone
Problem Description The doggie found a bone in an ancient maze, which fascinated him a lot. However, ...
- Perl字符贪吃蛇
一时兴起,想试试能不能用perl实现字符贪吃蛇,算法如下: 定义2个数组@bg.@snake,@bg用来显示整个界面,@snake从蛇头开始保存蛇的坐标点. 蛇每移动一次,新的坐标点放到@snake头 ...
- CEF3设置cookie
#include "CEF3Helper.h" #include "../include/cef_app.h" #include "../includ ...
- Seurat V3.0
最新版V3文档:https://satijalab.org/seurat/vignettes.html 不要再用V2的版本了,V3已经涵盖了V2所有的功能. 最新版3.0已经发布了,有重大更新,以前的 ...
- 方法重载与invokevirtual字节码指令的关系
1.方法重载 创建MyTest5类 public class MyTest5 { public void test(Grandpa grandpa){ System.out.println(" ...
- F12找到页面某一元素所绑定的点击事件
比如我要查看银行账号这个标签所绑定的事件. 操作过程中使用的是谷歌浏览器 第一步:在该元素上右键→检查 第二步:点击Event Listeners 这样就能看到该元素绑定的所有事件了 第三步:展开cl ...
- WebSocket始终保持连接的办法
在项目中,后台为了其实把处理结果主动推送个前端,因此使用了WebSocket. 但是问题来了,页面每跳转一次,socket都要重新关闭建立连接.这个资源消耗是很大的,而且线上环境随着并发量的增加会报错 ...
- ES6深入浅出-12 ES6新增的API(下)-1.录屏
String.includes es5里面判断字符串是否存在的方法 search searcg的厉害之处是可以使用正则 match正则的方式 repeat -1遍,就不合法 startsWith 判断 ...
- Sql server with as update用法
create table t1 ( id int,[names] varchar(100)) create table t2( id int,[names] varchar(100)) insert ...
- /var/spool/postfix
centos磁盘优化,发现/var/spool/postfix/maildrop下有大量文件. cron进程默认会将计划任务中所运行的脚本的警告.错误信息或者脚本输出信息发送给计划任务的所有者,而由于 ...