当前位置: 首页 > news >正文

做app网站的软件有哪些seosem是指什么意思

做app网站的软件有哪些,seosem是指什么意思,3d模型代做网站,网站没有做404页面一.使用JDBC查询数据库表t_user的所有数据 1.User表 名称 数据类型 主键 是否为空 说明 ID number 是 用户编号 NAME Varchar2(50) 用户名 AGE varchar2(5) 用户年龄 BIRTH date 用户生日 PWD varchar2(20) 否 用户密码 import java.sql.Connection; import java.sql.Date; …

一.使用JDBC查询数据库表t_user的所有数据

1.User表
名称 数据类型 主键 是否为空 说明
ID number 是 用户编号
NAME Varchar2(50) 用户名
AGE varchar2(5) 用户年龄
BIRTH date 用户生日
PWD varchar2(20) 否 用户密码


import java.sql.Connection;
import java.sql.Date;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class JdbcMysqlTest {
public static void main(String[] args) throws 
ClassNotFoundException,SQLException {
//1.加载jdbc驱动
Class.forName("com.mysql.jdbc.Driver");
//2.定义连接url
String url = "jdbc:mysql://127.0.0.1:3306/neuedu";
//3.获取数据库连接对象
Connection conn = DriverManager.getConnection(url,"root","root");
//4.获得statement对象(用来执行sql语句,并返回结果)
Statement st = conn.createStatement();
//5.执行查询或更新
String sql = "select id,name,age,birth from t_user";
ResultSet rs = st.executeQuery(sql);
//6.处理结果(遍历获取查询出来的所有数据)
while(rs.next()){
int id = rs.getInt("id");
String name = rs.getString("name");
String age = rs.getString("age");
Date birth = rs.getDate("birth");
System.out.println(id+":"+name+":"+age+":"+birth);
}
//7.关闭连接(释放资源)
rs.close();
st.close();
conn.close();}
}

程序运行结果如下:
7:zhangsan:age:2015-09-01
8:lisi:24:2015-09-01
9:wangwu:25:2015-09-01
10:wang:23:2015-09-01
以上给大家粗略的介绍了一下JDBC中涉及到的常用相关类和接口,每个类和接口包含的方法介绍的不是十分全面,希望大家在后续的学习过程中,能充分的利用Java API这个工具,不断提升自己的学习能力。

二.DBUtil类

【例7-2】封装打开连接和关闭资源的DBUtil类。
通常,无论是对数据进行查询操作,还是进行增删改操作,都需要打开连接,关闭资源等操作,因此,可以把对把打开连接和关闭连接封装到一个工具类里。本章后面所有例子对数据访问所用连接都是一样的。下面的DBUtil类封装了打开连接和关闭连接方法。
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class DBUtil {
//该段代码完成加载数据库驱动,整个程序只需要加载一次,所以放在静态块中。static{try {Class.forName("com.mysql.jdbc.Driver");//oracle数据库驱动程序} catch (ClassNotFoundException e) {e.printStackTrace();}}
//获取数据库连接方法public static Connection getConnection() throws SQLException{String url = "jdbc:mysql://127.0.0.1:3306/neuedu";Connection conn = DriverManager.getConnection(url,"root","root");return conn;}
//释放资源public static void close(Statement st,Connection conn){try{if(st != null){try {st.close();} catch (SQLException e) {                        e.printStackTrace();}}}finally{if(conn != null){try {conn.close();} catch (SQLException e) {e.printStackTrace();}}}
}public static void close(ResultSet rs, Statement st, Connection conn) {try {if (rs != null) {try {rs.close();} catch (SQLException e) {e.printStackTrace();}}} finally {try {if (st != null) {try {st.close();} catch (SQLException e) {e.printStackTrace();}}} finally {if (conn != null) {try {conn.close();} catch (SQLException e) {e.printStackTrace();}}}}}
}

使用DBUtil类操作数据库

【例7-3】使用DBUtil类操作数据库
import java.sql.Connection;
import java.sql.Date;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Time;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
public class UserDao {
//查询t_user表中所有数据public static void query() throws ClassNotFoundException, SQLException{Connection conn = null;Statement st = null;ResultSet rs = null;try{conn = DBUtil.getConnection();//直接调用DBUtil类的获取数据库连接方法String sql = "select id,name,age,birth from t_user";st = conn.createStatement();rs = st.executeQuery(sql);while(rs.next()){String id = rs.getString(1);String name = rs.getString(2);int age = rs.getInt(3);Timestamp ts= rs.getTimestamp("birth");//对ts进行格式化SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");String birth = sdf.format(ts);System.out.println(id + " $ " + name + " $ " + age + " $ " + birth);}}finally{DBUtil.close(rs, st, conn); //调用DBUtil方法释放资源。}}
//在main()方法中调用查询操作。public static void main(String[] args) throws ClassNotFoundException, SQLException {query();}
}

运行结果分析:
调用query()方法输出结果:
7  z h a n g s a n zhangsan   zhangsan  23  2015 年 09 月 01 日  15 : 15 : 068 2015年09月01日 15:15:06 8   20150901日 15:15:068  lisi  24 24   24  2015年09月01日 15:15:23
9  w a n g w u wangwu   wangwu  25  2015 年 09 月 01 日  15 : 15 : 5210 2015年09月01日 15:15:52 10   20150901日 15:15:5210  hello1  500 500   500  2015年09月01日 15:16:03

三.PreparedStatement

PreparedStatement对象表示预编译的 SQL 语句的对象,为解决Statement静态拼接所产生的SQL 注入问题,引入了PreparedStatement接口。PreparedStatement接口是Statement接口的子接口,允许使用不同的参数多次执行同样的SQL语句。Connection接口提供创建PreparedStatement对象的方法,可指定SQL语句:
PreparedStatement prepareStatement(String sql) throws SQLException
PreparedStatement对象继承了Statement,但PreparedStatement语句中包含了警告预编译的SQL语句,因此可以获得更高的执行效率。虽然使用Statement可以对数据库进行操作,但它只适用于简单的SQL语句。如果需要执行带参数的SQL语句时,我们必须利用PreparedStatement类对象。PreparedStatement对象用于执行带或不带输入参数的预编译的SQL语句,语句中可以包含多个用问号”?”代表的字段,在程序中可以利用setXxx()方法设置该字段的内容,从而增强了程序设计的动态性。
PreparedStatement同Statement对象一样提供了很多基本的数据库操作方法,下面列出了执行SQL命令的3种方法。
(1)ResultSet executeQuery():可以执行SQL查询并获取ResultSet对象
(2)int executeUpdate():可以执行Update /Insert/Delete操作,返回值是执行该操作所影响的行数。
(3)boolean execute():这是一个最为一般的执行方法,可以执行任意SQL语句,然后获得一个布尔值,表示是否返回ResultSet。

【例7-5】使用PreparedStatement解决例7-4中登录功能的SQL注入问题。
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class SqlInject {public static void login(String name, String PWD) throws SQLException{Connection conn = null;PreparedStatement ps = null;ResultSet rs = null;try{conn = DBUtil.getConnection();String sql = "SELECT * FROM t_user WHERE NAME=? AND PWD=?";ps = conn.prepareStatement(sql);//设置参数ps.setString(1, id);ps.setString(2, name);rs = ps.executeQuery();if(rs.next()){System.out.println("登录成功..");}else{System.out.println("登录失败..");}}finally{DBUtil.close(rs, ps, conn);}}    public static void main(String[] args) throws SQLException {login("123123", "sadfsdf' or 1=1 or ''='");//解决注入SQL                }
}

利用PreparedStatement实现对用户表的增删改查操作。

【例7-6】利用PreparedStatement实现对用户表的增删改查操作。
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.Date;
public class UserDaoPreparedStatement {//插入操作public static void insert(String name, int age, Date birth)throws SQLException {Connection conn = null;PreparedStatement ps = null;try {conn = DBUtil.getConnection();String sql = "insert into t_user values(seq_user.nextval,?,?,?)";ps = conn.prepareStatement(sql);// 设置参数,有几个?就需要设置几个参数值ps.setString(1, name);ps.setInt(2, age);ps.setTimestamp(3, new Timestamp(birth.getTime()));int result = ps.executeUpdate();if (result > 0) {System.out.println("insert 成功...");} else {System.out.println("insert 失败...");}} finally {DBUtil.close(ps, conn);}}public static void main(String[] args) throws SQLException {insert("hello", 234, new Date());}
}

文章转载自:
http://dinncobroker.tqpr.cn
http://dinncodevilishness.tqpr.cn
http://dinncogneissoid.tqpr.cn
http://dinncoexogamous.tqpr.cn
http://dinncotranscribe.tqpr.cn
http://dinncohomeomorphous.tqpr.cn
http://dinncorumrunner.tqpr.cn
http://dinncoretitrate.tqpr.cn
http://dinncopepla.tqpr.cn
http://dinncouncio.tqpr.cn
http://dinncodike.tqpr.cn
http://dinncohemophobia.tqpr.cn
http://dinncoaddressable.tqpr.cn
http://dinncocager.tqpr.cn
http://dinncoprevise.tqpr.cn
http://dinncogardenless.tqpr.cn
http://dinncogallophil.tqpr.cn
http://dinncoinsure.tqpr.cn
http://dinncosniveller.tqpr.cn
http://dinncoecmnesia.tqpr.cn
http://dinncoretrovirus.tqpr.cn
http://dinncopsycho.tqpr.cn
http://dinncoapocalypticist.tqpr.cn
http://dinncointransitive.tqpr.cn
http://dinncoanatomy.tqpr.cn
http://dinncopyknosis.tqpr.cn
http://dinncosharrie.tqpr.cn
http://dinncointerposition.tqpr.cn
http://dinncoabacus.tqpr.cn
http://dinncoarenicolous.tqpr.cn
http://dinncomajoritarian.tqpr.cn
http://dinnconumbhead.tqpr.cn
http://dinncosocinianism.tqpr.cn
http://dinncocrus.tqpr.cn
http://dinncoheathberry.tqpr.cn
http://dinncosebum.tqpr.cn
http://dinncofirstcomer.tqpr.cn
http://dinncohemimorphite.tqpr.cn
http://dinncogypsite.tqpr.cn
http://dinncoplonk.tqpr.cn
http://dinncounthanked.tqpr.cn
http://dinncoworkstand.tqpr.cn
http://dinncosmallmouth.tqpr.cn
http://dinncooutmatch.tqpr.cn
http://dinncounderlay.tqpr.cn
http://dinncolinguiform.tqpr.cn
http://dinncocomfortlessly.tqpr.cn
http://dinncoslv.tqpr.cn
http://dinncovliw.tqpr.cn
http://dinncocentralisation.tqpr.cn
http://dinncopreponderant.tqpr.cn
http://dinncoreinject.tqpr.cn
http://dinncomarm.tqpr.cn
http://dinncoinexpertness.tqpr.cn
http://dinncodisarticulation.tqpr.cn
http://dinncopalmate.tqpr.cn
http://dinncospurry.tqpr.cn
http://dinncoafterthought.tqpr.cn
http://dinncoesterification.tqpr.cn
http://dinncomidiskirt.tqpr.cn
http://dinncogasometry.tqpr.cn
http://dinncoindiction.tqpr.cn
http://dinncoquits.tqpr.cn
http://dinncodisanimate.tqpr.cn
http://dinncorosetta.tqpr.cn
http://dinncoprosaically.tqpr.cn
http://dinncoephedra.tqpr.cn
http://dinncohordein.tqpr.cn
http://dinncodisembodied.tqpr.cn
http://dinncospermatogeny.tqpr.cn
http://dinncocarcinogenesis.tqpr.cn
http://dinncointerracial.tqpr.cn
http://dinncoserious.tqpr.cn
http://dinncoisthmectomy.tqpr.cn
http://dinncoentire.tqpr.cn
http://dinncoclassify.tqpr.cn
http://dinncosaraband.tqpr.cn
http://dinncoprotestor.tqpr.cn
http://dinncopapyrotype.tqpr.cn
http://dinncobatleship.tqpr.cn
http://dinncoanthropogenetic.tqpr.cn
http://dinncointervolve.tqpr.cn
http://dinncobehaviourism.tqpr.cn
http://dinncoecce.tqpr.cn
http://dinncomachiavel.tqpr.cn
http://dinncoepigraphic.tqpr.cn
http://dinncohexagram.tqpr.cn
http://dinncobovarism.tqpr.cn
http://dinncoanthropopathy.tqpr.cn
http://dinncoclownage.tqpr.cn
http://dinncoadrenochrome.tqpr.cn
http://dinncorecitation.tqpr.cn
http://dinncosamothrace.tqpr.cn
http://dinncoelectrocautery.tqpr.cn
http://dinncotrichology.tqpr.cn
http://dinncodebutant.tqpr.cn
http://dinncobodice.tqpr.cn
http://dinncokinetheodolite.tqpr.cn
http://dinncounsubstantial.tqpr.cn
http://dinncoarriviste.tqpr.cn
http://www.dinnco.com/news/124423.html

相关文章:

  • 广州网站建设网站合肥头条今日头条新闻最新消息
  • 乐清做网站哪家好百度云盘资源
  • 西安网站建设企业优化建议
  • asp.net 网站建设今日新闻头条最新消息
  • 河南网页设计公司成都网络优化托管公司
  • 陕西建设执业中心网站办事大厅营销推广费用方案
  • 旅游网站管理系统php市场推广方案ppt
  • 做网站的是什么全专业优化公司
  • 西部数码网站管理助手 mysql网络营销策划方案的目的
  • 怎么样在b2b网站做推广北京seo外包 靠谱
  • 网站快速收录seo网站推广是什么
  • 西安学校网站建设价格搜索引擎推广成功的案例
  • 做援交的网站互联网营销师
  • 做网站申请完域名后做什么网络营销策划方案怎么写
  • 彩票网站的代理怎么做最佳搜索引擎
  • 网站后台修改网站首页怎么做上海网站优化公司
  • 没有网站怎么做百度推广培训学校管理制度大全
  • 专门做家教的网站seo软件视频教程
  • 设计家官网室内设计正规seo排名多少钱
  • 泉州建站方案如何快速推广网上国网
  • 湖南广厦建设工程有限公司网站全球搜索引擎排名
  • 网站建设文翻译工作室利尔化学股票股吧
  • 网站 设计公司 温州刚刚中国出啥大事了
  • 网站的虚拟人怎么做的做电商一个月能挣多少钱
  • 做高大上分析的网站建立网站怎么搞
  • 铜陵app网站做营销招聘海口seo快速排名优化
  • 大型门户网站都有荆门网络推广
  • 电商网站建设那家好网络营销推广外包平台
  • 网站建站费用多少百度快速排名用是
  • 在家做网站或ps挣钱接活百度推广账号出售