当前位置: 首页 > 编程日记 > 正文

经常用得到的安卓数据库基类

  1. //创建数据库  
  2. public class DBCreate {  
  3. public static void CreateDatabase(SQLiteDatabase db) {  
  4. db.beginTransaction();
  5. try {  
  6. create_NetTaskBuffer(db);
  7. insert_SQL(db);
  8. db.setTransactionSuccessful();
  9. catch (Exception e) {  
  10. e.printStackTrace();
  11. finally {  
  12. db.endTransaction();
  13. }
  14. }
  15. // 缓存  
  16. private static void create_NetTaskBuffer(SQLiteDatabase db) {  
  17. db.execSQL("DROP TABLE IF EXISTS NetTaskBuffer");  
  18. StringBuilder sql = new StringBuilder();  
  19. sql.append("CREATE TABLE IF NOT EXISTS NetTaskBuffer (");  
  20. sql.append(" id INTEGER PRIMARY KEY AUTOINCREMENT,"); // 这一列不能修改  
  21. sql.append(" label TEXT COLLATE NOCASE,"); //  
  22. sql.append(" param TEXT COLLATE NOCASE,"); //  
  23. sql.append(" result TEXT COLLATE NOCASE,"); //  
  24. sql.append(" remark TEXT COLLATE NOCASE,");  
  25. sql.append(" time LONG)"); //  
  26. db.execSQL(sql.toString());
  27. }
  28. // 插入语句,初始化数据库使用  
  29. private static void insert_SQL(SQLiteDatabase db) {  
  30. }
  31. }
  32. //----------------------数据库操作基类--------------------------------------//  
  33. /** 
  34.  * 数据库基本操作类,数据库的创建,更新的操作都在这里进行 
  35.  *  
  36.  * @author yizhe 
  37.  * @date 2014-9-11 
  38.  */  
  39. public abstract class DBHelper extends SQLiteOpenHelper {  
  40. static String name = "hk.db"; // 数据库名称  
  41. static CursorFactory cursorFactory = null;  
  42. static int version = 1000;// 初始版本:1000  
  43. Context context;
  44. protected ContentValues contentValues; // cursor对象转行中介,给子类使用  
  45. protected String tableName;  
  46. protected DBHelper(Context context, String tableName) {  
  47. super(context, name, cursorFactory, version);  
  48. this.context = context;  
  49. this.tableName = tableName;  
  50. }
  51. /** 
  52.      * 软件第一次安装的时候会调用,覆盖安装不会调用 
  53.      */  
  54. public void onCreate(SQLiteDatabase db) {  
  55. // 所有表的创建过程都在这里进行  
  56. DBCreate.createDatabase(db);
  57. }
  58. /** 
  59.      * 覆盖安装,当版本号version发生变化的时候,这个方法才会被调用,而且只执行一次 
  60.      */  
  61. public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {  
  62. onCreate(db);
  63. // if (oldVersion < 109) {  
  64. // onCreate(db);  
  65. // } else {  
  66. // }  
  67. }
  68. /** 
  69.      * 每次成功打开数据库后首先被执行 
  70.      */  
  71. public void onOpen(SQLiteDatabase db) {  
  72. super.onOpen(db); // 每次成功打开数据库后首先被执行  
  73. }
  74. public void finalize() {  
  75. close();
  76. }
  77. // --------------------------sql方法---------------------------------//  
  78. /** 
  79.      * 执行sql,没有返回 
  80.      */  
  81. public void execSQL(String sql) {  
  82. System.out.println("==execSQL==" + sql);  
  83. SQLiteDatabase db = getWritableDatabase();
  84. db.execSQL(sql);
  85. db.close();
  86. }
  87. /** 
  88.      * 批量执行sql,内部启用事务 
  89.      *  
  90.      * @param list 
  91.      *            sql列表 
  92.      * @return 是否执行成功 
  93.      */  
  94. public boolean execSQLBatch(ArrayList<String> list) {  
  95. SQLiteDatabase db = getWritableDatabase();
  96. db.beginTransaction();
  97. try {  
  98. for (String sql : list) {  
  99. db.execSQL(sql);
  100. }
  101. db.setTransactionSuccessful();
  102. catch (Exception e) {  
  103. e.printStackTrace();
  104. return false;  
  105. finally {  
  106. db.endTransaction();
  107. db.close();
  108. }
  109. return true;  
  110. }
  111. /** 
  112.      * 根据id删除记录 
  113.      *  
  114.      * @param id 
  115.      *            表中必须有"id"字段 
  116.      * @return the number of rows affected if a whereClause is passed in, 0 
  117.      *         otherwise. To remove all rows and get a count pass "1" as the 
  118.      *         whereClause. 
  119.      */  
  120. public int delete(int id) {  
  121. SQLiteDatabase db = getWritableDatabase();
  122. int result = db.delete(tableName, "id=?", new String[] { id + "" });  
  123. db.close();
  124. return result;  
  125. }
  126. /** 
  127.      * 删除: 只需要写where 条件(不带where) 和 参数 
  128.      *  
  129.      * @param whereStr 
  130.      *            例如: "id=?" 
  131.      * @param arr 
  132.      *            例如: new String[] { "123" } 
  133.      * @return 受影响的行 
  134.      */  
  135. public int delete(String whereStr, String[] arr) {  
  136. SQLiteDatabase db = getWritableDatabase();
  137. int result = db.delete(tableName, whereStr, arr);  
  138. db.close();
  139. return result;  
  140. }
  141. /** 
  142.      * 清空表 
  143.      */  
  144. public void clearTable() {  
  145. SQLiteDatabase db = getWritableDatabase();
  146. db.execSQL("delete from " + tableName);  
  147. db.close();
  148. }
  149. /** 
  150.      * 通用查询,多用于事务中 
  151.      */  
  152. public static Cursor Query(SQLiteDatabase db, String sql) {  
  153. System.out.println("==Query==" + sql);  
  154. return db.rawQuery(sql, new String[] {});  
  155. }
  156. /** 
  157.      * 通用执行sql,,多用于事务中 
  158.      *  
  159.      */  
  160. public static void execSQL(SQLiteDatabase db, String sql) {  
  161. System.out.println("==execSQL==" + sql);  
  162. db.execSQL(sql);
  163. }
  164. }
  165. //-------------------------下面是一个具体实现的DEMO-------------------------------//  
  166. /** 
  167.  * dao类,实现基本的数据库操作<br/> 
  168.  * 需要保存到数据库中的对象的属性不能使用基本类型,建议只使用Integer 和 String<br/> 
  169.  * 做为通用对象,从demo创建只要修改tableName即可 
  170.  *  
  171.  * @author yizhe 
  172.  * @date 2012-5-18 
  173.  */  
  174. public class NetTaskBufferDao extends DBHelper {  
  175. int expiryDays = 10; // 数据缓存有效期  
  176. public NetTaskBufferDao(Context context) {  
  177. super(context, "NetTaskBuffer");  
  178. }
  179. // pojo的整数都需要使用Long类型 或者Integer类型 建议使用Long  
  180. public void iniContentValues(NetTaskBuffer pojo) {  
  181. contentValues = new ContentValues();  
  182. contentValues.put("id", pojo.id);  
  183. contentValues.put("label", pojo.label);  
  184. contentValues.put("param", pojo.param);  
  185. contentValues.put("result", pojo.result);  
  186. contentValues.put("remark", pojo.remark);  
  187. contentValues.put("time", pojo.time);  
  188. }
  189. public NetTaskBuffer setBaseItem(Cursor cursor) {  
  190. NetTaskBuffer pojo = new NetTaskBuffer();  
  191. pojo.id = cursor.getInt(cursor.getColumnIndex("id"));  
  192. pojo.label = cursor.getString(cursor.getColumnIndex("label"));  
  193. pojo.param = cursor.getString(cursor.getColumnIndex("param"));  
  194. pojo.result = cursor.getString(cursor.getColumnIndex("result"));  
  195. pojo.remark = cursor.getString(cursor.getColumnIndex("remark"));  
  196. pojo.time = cursor.getLong(cursor.getColumnIndex("time"));  
  197. return pojo;  
  198. }
  199. // --------------------自定义方法--------------------------------//  
  200. public String getBuffer(String label, String param) {  
  201. String sql = "select * from " + tableName  
  202. " where label=? and param=? ";  
  203. NetTaskBuffer obj = getOneAsSQL(sql, new String[] { label, param });  
  204. if (null == obj) {  
  205. return null;  
  206. }
  207. Date time = new Date(obj.time);  
  208. Calendar c = Calendar.getInstance();
  209. c.add(Calendar.DAY_OF_MONTH, -expiryDays);
  210. if (time.compareTo(c.getTime()) < 0) {  
  211. delete(obj.id);
  212. return null;  
  213. }
  214. return obj.result;  
  215. }
  216. public String getBuffer(String label, String param, String remark) {  
  217. String sql = "select * from " + tableName  
  218. " where label=? and param=? and remark=?";  
  219. NetTaskBuffer obj = getOneAsSQL(sql, new String[] { label, param,  
  220. remark });
  221. if (null == obj) {  
  222. return null;  
  223. }
  224. Date time = new Date(obj.time);  
  225. Calendar c = Calendar.getInstance();
  226. c.add(Calendar.DAY_OF_MONTH, -expiryDays);
  227. if (time.compareTo(c.getTime()) < 0) {  
  228. delete(obj.id);
  229. return null;  
  230. }
  231. return obj.result;  
  232. }
  233. public void deleteBuffer(String label) {  
  234. String whereSql = " label=?";  
  235. delete(whereSql, new String[] { label });  
  236. }
  237. public void deleteBuffer(String label, String param) {  
  238. String whereSql = " label=? and param=?";  
  239. delete(whereSql, new String[] { label, param });  
  240. }
  241. public void deleteBuffer(String label, String param, String remark) {  
  242. String whereSql = " label=? and param=? and remark=?";  
  243. delete(whereSql, new String[] { label, param, remark });  
  244. }
  245. // --------------------基础方法---------------------------------//  
  246. /** 
  247.      * 根据sql获取list 
  248.      */  
  249. public ArrayList<NetTaskBuffer> getListAsSQL(String sql) {  
  250. SQLiteDatabase db = getReadableDatabase();
  251. Cursor cursor = db.rawQuery(sql, new String[] {});  
  252. ArrayList<NetTaskBuffer> itemList = new ArrayList<NetTaskBuffer>();  
  253. for (cursor.moveToFirst(); !(cursor.isAfterLast()); cursor.moveToNext()) {  
  254. itemList.add(setBaseItem(cursor));
  255. }
  256. cursor.close();
  257. db.close();
  258. return itemList;  
  259. }
  260. /** 
  261.      * 根据ID获取一条记录 
  262.      */  
  263. public NetTaskBuffer getById(int id) {  
  264. String sql = "select * from " + tableName + " where id=" + id;  
  265. return getOneAsSQL(sql, null);  
  266. }
  267. /** 
  268.      * 返回结果中的提一条记录 
  269.      */  
  270. public NetTaskBuffer getOneAsSQL(String sql, String[] arr) {  
  271. SQLiteDatabase db = getReadableDatabase();
  272. Cursor cursor = db.rawQuery(sql, arr);
  273. try {  
  274. if (null != cursor && cursor.getCount() > 0) {  
  275. cursor.moveToFirst();
  276. return setBaseItem(cursor);  
  277. }
  278. finally {  
  279. cursor.close();
  280. db.close();
  281. }
  282. return null;  
  283. }
  284. /** 
  285.      * 保存对象到数据库,自动判断插入还是更像 
  286.      *  
  287.      * @return 返回更新的记录数,或者 插入数据的id,如果返回值<=0表示失败 
  288.      */  
  289. public long save(NetTaskBuffer pojo) {  
  290. if (null == pojo.time || 0 == pojo.time) {  
  291. pojo.time = new Date().getTime();  
  292. }
  293. Long idOrEffectRows = 0l;
  294. if (null == pojo.id || pojo.id < 1) {  
  295. idOrEffectRows = insert(pojo);
  296. else {  
  297. idOrEffectRows = (long) update(pojo);  
  298. }
  299. return idOrEffectRows;  
  300. }
  301. /** 
  302.      * 添加数据,自动插入id 
  303.      *  
  304.      * @return the row ID of the newly inserted row, or -1 if an error occurred 
  305.      */  
  306. public long insert(NetTaskBuffer pojo) {  
  307. SQLiteDatabase db = getWritableDatabase();// 获取可写SQLiteDatabase对象  
  308. iniContentValues(pojo); // ContentValues类似map,存入的是键值对  
  309. long result = db.insert(tableName, null, contentValues);  
  310. if (result != -1) {  
  311. pojo.id = (int) result;  
  312. }
  313. db.close();
  314. return result;  
  315. }
  316. /** 
  317.      * 根据ID更新记录的,跟插入的很像 
  318.      *  
  319.      * @return the number of rows affected 
  320.      *  
  321.      */  
  322. public int update(NetTaskBuffer pojo) {  
  323. SQLiteDatabase db = getWritableDatabase();
  324. iniContentValues(pojo); // 初始化键值对  
  325. int result = db.update(tableName, contentValues, "id=?",  
  326. new String[] { pojo.id + "" });  
  327. db.close();
  328. return result;  
  329. }
  330. }

安卓标准数据库构建.zip (9.2 KB)

转载于:https://www.cnblogs.com/dongweiq/p/4045077.html

相关文章:

mysql5.7 zip安装配置_MySQL5.7的.zip文件的配置安装

由于MySQL5.7之后在javaEE中交互的端口发生了变化&#xff0c;而MySQL官网中5.6、5.7版本64位的只有.zip文件&#xff0c;而.zip文件不像直接下载installer一样可以获取到初始密码&#xff0c;需要通过管理员身份输入命令skip初始密码&#xff0c;所以记录.zip下安装配置过程。…

Linux vsftp配置详解

一.vsftpd说明:LINUX下实现FTP服务的软件很多,最常见的有vsftpd,Wu-ftpd和Proftp等.Red HatEnterprise Linux中默认安装的是vsftpd.访问FTP服务器时需要经过验证,只有经过了FTP服务器的相关验证,用户才能访问和传输文件.vsftpd提供了3种ftp登录形式:(1)anonymous(匿名帐号)使用…

top命令详解-性能分析

top命令是Linux下常用的性能分析工具&#xff0c;能够实时显示系统中各个进程的资源占用状况&#xff0c;常用于服务端性能分析。 top命令说明 [www.linuxidc.comlinuxidc-t-tomcat-188-193 ~]$ top top - 16:07:37 up 241 days, 20:11, 1 user, load average: 0.96, 1.13, 1.2…

leetcode-53 最大子序和

题目描述如下&#xff1a; 给定一个整数数组 nums &#xff0c;找到一个具有最大和的连续子数组&#xff08;子数组最少包含一个元素&#xff09;&#xff0c;返回其最大和。 示例: 输入: [-2,1,-3,4,-1,2,1,-5,4], 输出: 6 解释: 连续子数组 [4,-1,2,1] 的和最大&#xff0c;…

docker 离线安装 mysql_Oracle数据库之docker 离线环境安装oracle

本文主要向大家介绍了Oracle数据库之docker 离线环境安装oracle&#xff0c;通过具体的内容向大家展现&#xff0c;希望对大家学习Oracle数据库有所帮助。因测试需要&#xff0c;需在内网的测试环境搭建一套docker Oracle 11g环境进行测试&#xff0c;测试环境为redhat 6.6 安装…

ios Develop mark

App Distribution Guidehttps://developer.apple.com/library/ios/documaentation/IDEs/Conceptual/AppDistributionGuide/Introduction/Introduction.html#//apple_ref/doc/uid/TP40012582 马上着手开发 iOS 应用程序 (Start Developing iOS Apps Today)https://developer.app…

联想打字必须按FN+数字-fn打字

对于联想G40、14英寸系列的本本&#xff0c;好多时候无意间可能把数字键锁定了。 这时候要做的是&#xff1a;打开运行--输入OSK--打开虚拟屏幕键盘。这时候可以找到 选项---打开数字键盘。 有时候某些电脑上没有NUMLOCK这个键。当小键盘打开的时候就又numlock这个键了。这时候…

每日记载内容总结50

Maven中的dependencyManagement 意义【原文链接】 在Maven中dependencyManagement的作用其实相当于一个对所依赖jar包进行版本管理的管理器。 pom.xml文件中&#xff0c;jar的版本判断的两种途径&#xff1a; (1)&#xff1a;如果dependencies里的dependency自己没有声明versio…

leetcode-152 乘积最大子序列

题目描述&#xff1a; 给定一个整数数组 nums &#xff0c;找出一个序列中乘积最大的连续子序列&#xff08;该序列至少包含一个数&#xff09;。 示例 1: 输入: [2,3,-2,4] 输出: 6 解释: 子数组 [2,3] 有最大乘积 6。 示例 2: 输入: [-2,0,-1] 输出: 0 解释: 结果不能为…

js 监听 安卓事件_百行代码实现js事件监听实现跨页面数据传输

百行代码实现js事件监听实现跨页面数据传输使用场景类似消息队列的使用场景,支持同页面和跨页面通信,发送消息和接收消息技术原理跨页面通信:基于事件监听,通过监听 storage事件监听回调机制,实现跨页面通信,让每个只操作自身页面的操作同页面事件监听:发送事件时,查找回调函数…

Centos安装GD库

tar zxvf ncurses-5.6.tar.gz 进入目录 cd ncurses-5.6 生成 makefile文件&#xff0c;再进一步编译 ./configure --prefix/usr --with-shared --without-debug 编译&#xff0c;编译时间稍微长些&#xff0c;稍等make 编译好最后就是安装了 make install 下面才开始安装 GD库…

centos7安装mongodb3.4

先下载安装包&#xff0c;OS选择RHEL 7.0 Linux 64-bit x64&#xff0c;package选择Server。 这里OS选6.2应该也行&#xff0c;没试过&#xff0c;如果linux版本是6.*的话注意选这个&#xff0c;如果选择7.0安装的时候会提示缺少glibc依赖&#xff08;glibc版本过低&#xff09…

leetcode-300 最长上升子序列

题目描述&#xff1a; 给定一个无序的整数数组&#xff0c;找到其中最长上升子序列的长度。 示例: 输入: [10,9,2,5,3,7,101,18] 输出: 4 解释: 最长的上升子序列是 [2,3,7,101]&#xff0c;它的长度是 4。 说明: 可能会有多种最长上升子序列的组合&#xff0c;你只需要输出对…

转载自——Json.net动态序列化以及对时间格式的处理

关于我工作中对Json处理的东西 第一:动态序列化类 第二:时间格式处理 通常我们一个类里 可能有十到更多的属性,但是我们序列化通常只需要序列化其中的 三到五个这样的话就会有多余的数据 如果 我只想序列化 id 跟name如何处理 这是我找的网上的方法: using Newtonsoft.Json…

congratulation的用法_congratulation的用法

congratulation用作名词&#xff0c;表示祝贺&#xff0c;恭喜&#xff1b;congratulation表示抽象意义的“祝贺”时&#xff0c;为不可数名词。表示祝贺词时&#xff0c;用作可数名词。1.表示抽象意义的“祝贺”时&#xff0c;为不可数名词。I sent her a gift as a token of …

腾讯微博API时间线相关接口返回的微博信息中head值使用问题

腾讯微博API时间线相关接口返回的微博信息中head值表示作者头像url&#xff0c;这个链接直接访问并不能使用&#xff0c;需要再附加一个参数指定图片的大小&#xff08;100、50&#xff09;&#xff0c;比如&#xff1a;[head]/100。

java实现https请求

参考&#xff1a; https://www.cnblogs.com/chinway/p/5802541.html java 实现https请求 JSSE是一个SSL和TLS的纯Java实现&#xff0c;通过JSSE可以很容易地编程实现对HTTPS站点的访问。但是&#xff0c;如果该站点的证书未经权威机构的验证&#xff0c;JSSE将拒绝信任该证书从…

设计模式 之美 --- 初篇

接下来的一段时间将按照如下体系导图&#xff0c;对23种设计模式 按照自己的理解一一总结&#xff0c;为后续工作中持续灵活使用做好积累。 学习应用 设计模式的过程有如下好处 提高复杂代码的设计开发能力让阅读源码 和 学习框架事半功倍告别被别人吐槽的烂代码为职场发展做…

C语言中将0到1000的浮点数用强制指针类型转换的方式生成一幅图像

搞过计算机图像的人都知道&#xff0c;图像中的每一个像素通常为一个整型数&#xff0c;它可以分成4个无符号的char类型&#xff0c;以表示其RGBA四个分量。一幅图像可以看做是一个二维整型数组。这里我会生成一个float数组&#xff0c;其数组大小为1000000&#xff0c;刚好100…

mysql用户控制登录_MySql用户权限控制_MySQL

bitsCN.comMySql用户权限控制本文将介绍&#xff2d;ySql创建帐号&#xff0c;删除帐号&#xff0c;设置和介绍各种帐号的权限创建用户帐号&#xff1a; www.bitsCN.com[sql]CREATE USER user_name IDENTIFIED BY your_password;改名[sql]RENAME USER old_name TO new_name;删除…

[python] 从GPS坐标获取国家名

目标比较明确&#xff0c;就是从GPS坐标得到它所在的国家。网上可以找的比较典型的解决方案是利用一些网站&#xff08;例如Google&#xff09;的webservice来完成这个任务&#xff0c;但是这些解决方案有一个比较大的弱点&#xff0c;就是这些webservice会限制请求的次数&…

Djiango模板语言DTL

一、变量 def dtl(request):num 3.14ss abc123嘿嘿# return render(request, django_dtl.html, {number: num, ss: ss})result Truelist [1, 2, 3, 4, 5]dic {name: owen, age: 28}# 函数不能带有参数&#xff0c;模板中{{ fn }} 本质就是调用函数拿到函数值&#xff08;函…

设计模式 之美 -- 面向对象(C/C++分别实现)

文章目录前言封装C实现C 实现继承C 实现C实现前言 为了保证代码的可复用性、可扩展性、可维护性&#xff0c;我们提出了面向对象的思想。 面向对象的核心特性有以下几个 封装特性 信息隐藏或者数据访问保护。类通过暴露有限的访问接口&#xff0c;授权外部仅能通过类提供的方…

数据结构编程实战汇总

出自数据结构与算法分析第二版&#xff08;C&#xff09; 一 引论二 算法分析三 表 栈 队列四 树五 散列六 优先队列七 排序 优先队列实现事件模拟 &#xff1a;http://maozj.iteye.com/blog/676567d堆 左式堆 斜堆&#xff1a; http://blog.csdn.net/yangtrees/article/detai…

同时支持三个mysql+sqlite+pdo的php数据库类_同时支持三个MySQL+SQLite+PDO的PHP数据库类...

PHP学习教程文章简介&#xff1a; 同时支持三个MySQLSQLitePDO的PHP数据库类使用方法: // mysql connect $db new SQL(mysql:hostlocalhost;database21andy_blog;, 21andy.com_user, 21andy.com_password); // PDO SQLite3 connect $db new SQL(pdo:database/21andy.com/21an…

VB6基本数据库应用(五):数据的查找与筛选

同系列的第五篇&#xff0c;上一篇在&#xff1a;http://blog.csdn.net/jiluoxingren/article/details/9633139 数据的查找与筛选 第4篇发布到现在已经过了4天&#xff0c;很抱歉&#xff0c;学生党&#xff0c;还是悲催的高三&#xff0c;没办法&#xff0c;8月1就开学了。以后…

学习进度条(第一周)

学习进度条&#xff1a; 第一周 所花时间&#xff08;包括上课&#xff09; 5h 代码量&#xff08;行&#xff09; 150 博客量&#xff08;篇&#xff09; 2 了解到的知识点 这种主要是对上学期web知识的一个回顾&#xff0c;进行了第一次开学测验&#xff0c;了解了实…

设计模式 之美 -- 单例模式

为什么要使用单例&#xff1f; 一个类只允许创建一个对象或者实例。 背景简介&#xff1a;使用多线程并发访问同一个类&#xff0c;为了保证类的线程安全&#xff0c;可以有两种方法&#xff1a; 将该类定义为单例模式&#xff0c;即该类仅允许创建一个实例为该类的成员函数添…

(int),Int32.Parse() 和 Convert.toInt32() 的区别

在 C# 中&#xff0c;(int)&#xff0c;Int32.Parse() 和 Convert.toInt32() 三种方法有何区别? int 关键字表示一种整型&#xff0c;是32位的&#xff0c;它的 .NET Framework 类型为 System.Int32。 (int)表示使用显式强制转换&#xff0c;是一种类型转换。当我们从 int 类型…

MySQL留言板怎么创建_如何使用JSP+MySQL创建留言本(三)

如何使用JSPMySQL创建留言本(三)推荐查看本文HTML版本下面我们开始建立留言的页面&#xff01;import "java.util.*"import "java.text.*"import"java.sql.*"import "java.io.*"import "java.lang.*"contentType"t…