JSP JDBC 读取SQL Server 数据2
<%--
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的更多相关文章
- JDBC连接SQL Server代码模板
* JDBC连接SQL Server数据库 代码模板* Connection: 连接数据库并担任传送数据的任务:* Statement : 执行SQL语句:* Re ...
- JDBC连接sql server数据库及其它
JDBC连接sql server数据库的步骤如下: 1.加载JDBC驱动程序: 在连接数据库之前,首先要加载想要连接的数据库的驱动到JVM(Java虚拟机), 这通过java.lang.Class类的 ...
- SQL server数据缓存依赖
SQL server数据缓存依赖有两种实现模式,轮询模式,通知模式. 1 轮询模式实现步骤 此模式需要SQL SERVER 7.0/2000/2005版本以上版本都支持 主要包含以下几 ...
- Oracle GoldenGate 12c实时捕获SQL Server数据
在Oracle GoldenGate 12c中,对一些最新的数据库提供了支持,比如SQL Server 2012/2014,当然12c也支持sql server 2008.主要新增特性有: 捕获进程可 ...
- JDBC连接sql server数据库的详细步骤和代码
JDBC连接sql server数据库的详细步骤和代码 JDBC连接sql server数据库的步骤如下: 1.加载JDBC驱动程序: 在连接数据库之前,首先要加载想要连接的数据库的驱动到JVM(Ja ...
- 浅谈SQL Server数据内部表现形式
在上篇文章 浅谈SQL Server内部运行机制 中,与大家分享了SQL Server内部运行机制,通过上次的分享,相信大家已经能解决如下几个问题: 1.SQL Server 体系结构由哪几部分组成? ...
- SQL Server数据归档的解决方案
SQL Server数据归档的解决方案 最近新接到的一项工作是把SQL Server中保存了四五年的陈年数据(合同,付款,报销等等单据)进行归档,原因是每天的数据增量很大,而历史数据又不经常使用, ...
- Infopath 2010 接收SQL Server数据
Infopath2010为我们提供了多种接收数据的方式,今天我来讲讲里面其中的一种直接读取SQL Server数据库表数据方法(高阶者的下面可以略省,只针对入门者). 1.选择数据库(SQL) 2.选 ...
- 详解SQL Server数据修复命令DBCC的使用
严重级别为 21 表示可能存在数据损坏. 可能的原因包括损坏的页链.损坏的 IAM 或该对象的 sys.objects目录视图中存在无效条目. 这些错误通常由硬件或磁盘设备驱动程序故障而引起. MS ...
随机推荐
- mysql索引底层的数据结构和算法
1. 为什么要用索引 索引在MySQL中也叫做“键”,是存储引擎用于快速找到记录的一种数据结构.索引对于良好的性能非常关键,尤其是当表中的数据量越来越大时,索引对于性能的影响愈发重要. 索 ...
- CODEVS_1227 方格取数2 网络流 最小费用流 拆点
原题链接:http://codevs.cn/problem/1227/ 题目描述 Description 给出一个n*n的矩阵,每一格有一个非负整数Aij,(Aij <= 1000)现在从(1, ...
- luogu P2659 美丽的序列
题目背景 GD是一个热衷于寻求美好事物的人,一天他拿到了一个美丽的序列. 题目描述 为了研究这个序列的美丽程度,GD定义了一个序列的“美丽度”和“美丽系数”:对于这个序列的任意一个区间[l,r],这个 ...
- Codeforces 959 E Mahmoud and Ehab and the xor-MST
Discription Ehab is interested in the bitwise-xor operation and the special graphs. Mahmoud gave him ...
- Chrome常用URL命令(伪URL)
在Chrome地址栏输入chrome://chrome-urls/可以看到所有的Chrome支持的伪RUL 1.chrome://accessibility/ 可达性分析,默认是关闭的,点击acces ...
- iOS 内存管理实践
内存管理实践 尽管基本的概念在内存管理策略文章中简单得阐述了,但是还有一些实用的步骤让你更容易管理内存:有助于确保你的程序最大限度地减少资源需求的同时,保持可靠和强大. 使用“访问器方法”让内存管理更 ...
- VisualSVN Server 导入已存在的库
http://blog.csdn.net/lidatgb/article/details/7984220 早些时候建立过一个SVN Server的库,后来觉得库的名字太长了,随意换了一 ...
- sqlfairy用法
要画一个数据库的ER图,我比较懒,就想用工具来生成. 找了一下,发现一个不错的工具,名字叫sal-fairy 很强大,可以有很多用处. 其中有一个命令sqlt-graph,可以完成生成ER图. 用法如 ...
- fedora关闭防火墙
sudo systemctl stop iptables sudo sytemctl stop firewalld
- android项目大全,总有你所需的
注:打开请贴网址.有些直接通过链接打开的不对. 1.相对布局实例 http://kukuqiu.iteye.com/blog/1018396 2.Log图文具体解释(Log.v,Log.d,Log. ...