繁体   English   中英

创建使用数据库的Java应用程序我需要知道些什么?

[英]What do I need to know to make a Java application that uses a database?

自从我开始使用NetBeans以来,我已经学到了一些强大的方法来抽象化具有自动生成的UI,Bean绑定以及其他很多东西的Java数据库应用程序的创建过程,而我目前对此尚不清楚。 (我讨厌成为新手)。 问题是, 我该怎么做我实际上想做的基本事情 我读过的教程对在IDE中能够连接和处理数据库以及如何创建和绑定一些UI滑块和复选框到表列等有很大帮助。但是我在哪里可以了解到如何使自己的代码做到这一点? 抽象是很好的方法,但对于我现在需要做的事情,它对我来说毫无用处。

谁能推荐我一些好的资源或教程来学习这一点? 我发现的一些事实并没有像我希望让我的项目进行那样有用...

JDBC教程是一个很好的起点

简介片段

The JDBC API is a Java API that can access any kind of tabular data, 
especially data stored in a Relational Database.

JDBC helps you to write java applications that manage these three programming 
activities:

   1. Connect to a data source, like a database
   2. Send queries and update statements to the database
   3. Retrieve and process the results received from the database in answer to 
      your query

      The following simple code fragment gives a simple example of
these three steps:
  Connection con = DriverManager.getConnection
             ( "jdbc:myDriver:wombat", "myLogin","myPassword");

  Statement stmt = con.createStatement();
  ResultSet rs = stmt.executeQuery("SELECT a, b, c FROM Table1");
  while (rs.next()) {
    int x = rs.getInt("a");
    String s = rs.getString("b");
    float f = rs.getFloat("c");
  }
This short code fragment instantiates a DriverManager object to 
connect to a database driver and log into the database, instantiates a 
Statement object that carries your SQL language query to the database; 
instantiates a ResultSet object that retrieves the results of your query, 
and executes a simple while loop, which retrieves and displays those 
results. It's that simple.

还有上谷歌图书提供书籍预览这里

试试Sun的JDBC简介

一个熟悉JDBC的人,您可能要考虑使用Spring对JDBC的支持 它提供了比标准库更好的API(比标准库更好),用于通过JDBC访问数据库

我上次查看JDBC教程时,其中包含许多代码示例,如果它们在实际应用中使用的话,它们可能是SQL注入的秘诀。 我不得不讲授有关JDBC的课程,并且应该使用本教程,但是我必须通过安全性讲座来补充它。

阅读jdbc教程后,请注意以下基本概念:-连接-语句-查询-结果集

DB授权属于连接,查询是对“做什么”的描述-获取数据或更新,在某些情况下结果集可能是可更新的(!)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM