`
z610
  • 浏览: 37748 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Basic JDBC example

    博客分类:
  • java
 
阅读更多

String connectionURL = "jdbc:mysql://localhost:3306/test";
		// Change the connection string according to your db, ip, username and password

		Connection con = null;
		try {

			// Load the Driver class.
			Class.forName("com.mysql.jdbc.Driver");
			// If you are using any other database then load the right driver here.

			// Create the connection using the static getConnection method
			con = DriverManager.getConnection(connectionURL, "aaa", "aaaa");

			// Create a Statement class to execute the SQL statement
			Statement stmt = con.createStatement();

			Random random = new Random();
			int status = random.nextInt(2);
			System.out.println(status);
			
			String sql = "update test set status = " + status + " where id = 1";

			stmt.executeUpdate(sql);

		} catch (SQLException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			if(con != null) {
				try {
					con.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
		}
 
分享到:
评论

相关推荐

    Spring 各种例子:Spring Data Elasticsearch,JDBC,JPA,LDAP,MongoDB

    - basic:展示了Spring Data JDBC的基本用法。 - immutables:展示了使用Immutables的Spring Data JDBC用法。 4. Spring Data JPA: - eclipselink:展示了如何在Spring Boot和Eclipselink中使用Spring Data JPA...

    APress - The Definitive Guide to MySQL, 2nd Ed - 2004 - (By Laxxuss).chm

    Chapter 17 - Visual Basic, C#, ODBC Part IV - Reference Chapter 18 - SQL Reference Chapter 19 - MySQL Tools Chapter 20 - API Reference Part V - Appendices Appendix A - Glossary Appendix...

    Just.Spring.Jul.2011

    This example-driven book for Java developers delves into the framework's basic features, as well as advanced concepts such as containers. You'll learn how Spring makes Java Messaging Service easier ...

    Expert Oracle Database Architecture 2nd 原版PDF by Kyte

    are a Visual Basic programmer using ODBC, a Java programmer using EJBs and JDBC, or a Perl programmer using DBI Perl. This book does not promote any specific application architecture; it does not ...

    Hibernate Reference Documentation3.1

    3.3. JDBC connections 3.4. Optional configuration properties 3.4.1. SQL Dialects 3.4.2. Outer Join Fetching 3.4.3. Binary Streams 3.4.4. Second-level and query cache 3.4.5. Query Language Substitution...

    Geotools Java API 开发gis的参考资料

    org.geotools.data.jdbc.attributeio org.geotools.data.jdbc.datasource org.geotools.data.jdbc.fidmapper org.geotools.data.jdbc.referencing org.geotools.data.memory org.geotools.data.mif org.geo...

    pro spring batch

    The author also walks you through, from end to end, the design and implementation of a batch process based upon a theoretical real-world example. This includes basic project setup, implementation, ...

    restful restful所需要的jar包

    * Client JDBC connector based on the JDBC API, a custom request XML format and the JDBC WebRowSet interface for XML responses. * Client FILE connector supports GET, PUT and DELETE methods on files ...

    MySql存储过程编程.chm

    A Complete Example Section 16.5. Conclusion Chapter 17. Using MySQL Stored Programs with .NET Section 17.1. Review of ADO.NET Basics Section 17.2. Using Stored Programs in ADO.NET Section ...

    Hibernate+中文文档

    5. 对象/关系数据库映射基础(Basic O/R Mapping) 5.1. 映射定义(Mapping declaration) 5.1.1. Doctype 5.1.2. hibernate-mapping 5.1.3. class 5.1.4. id 5.1.5. composite-id 5.1.6. 鉴别器...

    Hibernate_3.2.0_符合Java习惯的关系数据库持久化

    5. 对象/关系数据库映射基础(Basic O/R Mapping) 5.1. 映射定义(Mapping declaration) 5.1.1. Doctype 5.1.2. hibernate-mapping 5.1.3. class 5.1.4. id 5.1.5. composite-id 5.1.6. 鉴别器...

    HibernateAPI中文版.chm

    5. 对象/关系数据库映射基础(Basic O/R Mapping) 5.1. 映射定义(Mapping declaration) 5.1.1. Doctype 5.1.2. hibernate-mapping 5.1.3. class 5.1.4. id 5.1.5. composite-id 5.1.6. 鉴别器...

    hibernate3.2中文文档(chm格式)

    5. 对象/关系数据库映射基础(Basic O/R Mapping) 5.1. 映射定义(Mapping declaration) 5.1.1. Doctype 5.1.2. hibernate-mapping 5.1.3. class 5.1.4. id 5.1.5. composite-id 5.1.6. 鉴别器...

    hibernate 教程

    基本的finder生成器(Basic finder generator) 15.2.4. 基于Velocity的渲染器/生成器(Velocity based renderer/generator) 15.3. 映射文件生成器(Mapping File Generation) 15.3.1. 运行此工具 16. ...

    hibernate

    基本的finder生成器(Basic finder generator) 15.2.4. 基于Velocity的渲染器/生成器(Velocity based renderer/generator) 15.3. 映射文件生成器(Mapping File Generation) 15.3.1. 运行此工具 16. ...

    Hibernate3的帮助文档

    6. 对象/关系数据库映射基础(Basic O/R Mapping) 6.1. 映射定义(Mapping declaration) 6.1.1. Doctype 6.1.2. hibernate-mapping 6.1.3. class 6.1.4. id 6.1.4.1. Generator 6.1.4.2. 高/低位算法(Hi/Lo ...

    最全Hibernate 参考文档

    3.3. JDBC连接 3.4. 可选的配置属性 3.4.1. SQL方言 3.4.2. 外连接抓取(Outer Join Fetching) 3.4.3. 二进制流 (Binary Streams) 3.4.4. 二级缓存与查询缓存 3.4.5. 查询语言中的替换 3.4.6. Hibernate的统计...

    Hibernate3+中文参考文档

    3.3. JDBC连接 3.4. 可选的配置属性 3.4.1. SQL方言 3.4.2. 外连接抓取(Outer Join Fetching) 3.4.3. 二进制流 (Binary Streams) 3.4.4. 二级缓存与查询缓存 3.4.5. 查询语言中的替换 3.4.6. Hibernate的统计...

    hibernate 框架详解

    6. 对象/关系数据库映射基础(Basic O/R Mapping) 6.1. 映射定义(Mapping declaration) 6.1.1. Doctype 6.1.2. hibernate-mapping 6.1.3. class 6.1.4. id 6.1.4.1. Generator 6.1.4.2. 高/低位算法(Hi/...

Global site tag (gtag.js) - Google Analytics