<%--
Created by IntelliJ IDEA.
User: hellohongfu
Date: 2017/12/21
Time: 0:16
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@page import="java.io.*,java.util.*" %>
<%@ page import="org.apache.poi.hssf.usermodel.*" %>
<%@ page import="org.apache.poi.poifs.filesystem.*" %>
<%@ page import="org.apache.poi.ss.usermodel.*" %>
<%@ page import="org.apache.poi.xssf.usermodel.*" %> <%@ page import="java.sql.*" %> <html>
<head>
<title>excel demo</title>
</head>
<body> <%
InputStream inp = new FileInputStream("c:\\demo.xlsx");
//InputStream inp = new FileInputStream("workbook.xlsx"); Workbook wb = WorkbookFactory.create(inp);
Sheet sheet = wb.getSheetAt(0);
for (int k = 1; k <= sheet.getLastRowNum(); k++){
Row row=sheet.getRow(k);
Cell cell = row.getCell(1);
if (cell != null){
String value =cell.getStringCellValue();
out.println("cell value:"+value+"<br>");
} } Row row = sheet.getRow(2);
Cell cell = row.getCell(3); out.println(cell.getStringCellValue());
if (cell == null)
cell = row.createCell(3);
cell.setCellType(CellType.STRING); // Write the output to a file
FileOutputStream fileOut = new FileOutputStream("workbook.xls");
wb.write(fileOut);
fileOut.close();
%> <table>
<thead>
<tr>
<th>
id
</th>
<th>
company
</th>
<th>
name
</th>
</tr>
</thead>
<tbody>
<%
String connectionUrl = "jdbc:sqlserver://DESKTOP-U9122RH;" +
"databaseName=ryqy;integratedSecurity=true;"; // Declare the JDBC objects.
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
out.println("test sql connection <br>");
try {
// Establish the connection.
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
con = DriverManager.getConnection(connectionUrl); // Create and execute an SQL statement that returns some data.
String querySql = "select * from account";
stmt = con.createStatement();
rs = stmt.executeQuery(querySql); // Iterate through the data in the result set and display it.
int isExists=0;
while (rs.next()) {
isExists=1; System.out.println(rs.getString(1) + " " + rs.getString(2)); String id=rs.getString(1);
String company=rs.getString(1);
String name =rs.getString(3); out.println("<tr><td>"+id+"</td><td>"+company+"</td><td>"+name+"</td></tr>"); }
out.println("test sql connection success <br>");
if(isExists==1)
{
out.println("已经存在不用再创建! <br>");
}else
{ out.println("不存在 <br>");
} } // Handle any errors that may have occurred.
catch (Exception e) {
e.printStackTrace();
out.println("test sql connection fault <br>");
} finally {
if (rs != null) try { rs.close(); } catch(Exception e) {}
if (stmt != null) try { stmt.close(); } catch(Exception e) {}
if (con != null) try { con.close(); } catch(Exception e) {}
}
%>
</tbody>
</table>
</body>
</html>

JSP JDBC 读取SQL Server 数据2的更多相关文章

  1. JDBC连接SQL Server代码模板

    *                  JDBC连接SQL Server数据库 代码模板* Connection: 连接数据库并担任传送数据的任务:* Statement :  执行SQL语句:* Re ...

  2. JDBC连接sql server数据库及其它

    JDBC连接sql server数据库的步骤如下: 1.加载JDBC驱动程序: 在连接数据库之前,首先要加载想要连接的数据库的驱动到JVM(Java虚拟机), 这通过java.lang.Class类的 ...

  3. SQL server数据缓存依赖

    SQL server数据缓存依赖有两种实现模式,轮询模式,通知模式. 1  轮询模式实现步骤 此模式需要SQL SERVER 7.0/2000/2005版本以上版本都支持        主要包含以下几 ...

  4. Oracle GoldenGate 12c实时捕获SQL Server数据

    在Oracle GoldenGate 12c中,对一些最新的数据库提供了支持,比如SQL Server 2012/2014,当然12c也支持sql server 2008.主要新增特性有: 捕获进程可 ...

  5. JDBC连接sql server数据库的详细步骤和代码

    JDBC连接sql server数据库的详细步骤和代码 JDBC连接sql server数据库的步骤如下: 1.加载JDBC驱动程序: 在连接数据库之前,首先要加载想要连接的数据库的驱动到JVM(Ja ...

  6. 浅谈SQL Server数据内部表现形式

    在上篇文章 浅谈SQL Server内部运行机制 中,与大家分享了SQL Server内部运行机制,通过上次的分享,相信大家已经能解决如下几个问题: 1.SQL Server 体系结构由哪几部分组成? ...

  7. SQL Server数据归档的解决方案

    SQL Server数据归档的解决方案   最近新接到的一项工作是把SQL Server中保存了四五年的陈年数据(合同,付款,报销等等单据)进行归档,原因是每天的数据增量很大,而历史数据又不经常使用, ...

  8. Infopath 2010 接收SQL Server数据

    Infopath2010为我们提供了多种接收数据的方式,今天我来讲讲里面其中的一种直接读取SQL Server数据库表数据方法(高阶者的下面可以略省,只针对入门者). 1.选择数据库(SQL) 2.选 ...

  9. 详解SQL Server数据修复命令DBCC的使用

    严重级别为 21 表示可能存在数据损坏. 可能的原因包括损坏的页链.损坏的 IAM 或该对象的 sys.objects目录视图中存在无效条目. 这些错误通常由硬件或磁盘设备驱动程序故障而引起. MS ...

随机推荐

  1. BZOJ 3130 [Sdoi2013]费用流 ——网络流

    [题目分析] 很容易想到,可以把P放在流量最大的边上的时候最优. 所以二分网络流,判断什么时候可以达到最大流. 流量不一定是整数,所以需要实数二分,整数是会WA的. [代码] #include < ...

  2. 【FFT求卷积】Problem D. Duel

    [AC] #include <stdio.h> #include <iostream> #include <string.h> #include <algor ...

  3. Lucas定理详解

    这篇博客是从另一位园友那里存的,但是当时忘了写原文的地址,如果有找到原文地址的请评论联系! Lucas定理解决的问题是组合数取模.数学上来说,就是求 \(\binom n m\mod p\).(p为素 ...

  4. ubuntu问题解答集锦

    一.su root提示认证失败 su root提示认证失败 ubuntu root是默认禁用了,不答应用root登陆,所以先要设置root密码.   执行:sudo passwd root 接着输入密 ...

  5. 数字串(codevs 1394)

    题目描述 Description 给你一个长度为n的数字串,数字串里会包含1-m这些数字.如果连续的一段数字子串包含了1-m这些数字,则称这个数字字串为NUM串.你的任务是求出长度最短的NUM串是什么 ...

  6. msp430入门学习41

    msp430的其他九 msp430入门学习

  7. 记一次ORM的权衡和取舍

    面对ORM的选型,有些人是根据自己熟悉程度来评判,有些人是根据他人的推荐来抉择,有些人觉得都差不多,随便了.当自己要真正做选择的时候,以上的这些依据都无法真正说服自己,因为不同的业务需求,不同的团队构 ...

  8. java list实现树形结构

    1.javabean import java.util.List; public class TreeNode { private String id; private String parentId ...

  9. MySQL 索引及其用法

    一.索引的作用 一般的应用系统,读写比例在10:1左右,而且插入操作和一般的更新操作很少出现性能问题,遇到最多的,也是最容易出问题的,还是一些复杂的查询操作,所以查询语句的优化显然是重中之重. 在数据 ...

  10. 创建es索引-格式化和非格式化

    创建es索引-格式化和非格式化 学习了:https://www.imooc.com/video/15768 索引有结构化和非结构化的区分: 1, 先创建索引,然后POST修改mapping 首先创建索 ...