如何在 netbeans 7.2.1 中将 Java 程序连接到 Derby

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14980382/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 18:05:09  来源:igfitidea点击:

How to connect a java program to Derby in netbeans 7.2.1

javasqldatabasederby

提问by Christian Burgos

im a novice programmer and i wanna know what is the basic way to connect a java program to Derby in netbeans 7.2.1. my prof asked me to make a program that lets me add, delete, save, search and edit entries from a table. i already know how to make a GUI java program in netbeans and how to make a database on netbeans too. i just want to know what are the basic codes to include in a program to enable it to connect on a database on netbeans 7.2.1. thank you for your time reading my question.

我是一名新手程序员,我想知道在 netbeans 7.2.1 中将 Java 程序连接到 Derby 的基本方法是什么。我的教授让我制作一个程序,让我可以添加、删除、保存、搜索和编辑表格中的条目。我已经知道如何在 netbeans 中制作 GUI Java 程序以及如何在 netbeans 上制作数据库。我只想知道程序中包含哪些基本代码,以使其能够连接到 netbeans 7.2.1 上的数据库。感谢您花时间阅读我的问题。

public void connection(){ try{ Class.forName("org.apache.derby.jdbc.ClientDriver"); String myDb = "jdbc:derby://localhost:1527/HWtrial"; Connection DBconn = DriverManager.getConnection(myDb, "",""); s1 = DBconn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); result = s1.executeQuery("SELECT * from HWSTUD"); result.next(); result.last(); }catch(Exception ex){ JOptionPane.showMessageDialog(null,"Cannot Connect to Database", "Error Message", JOptionPane.OK_OPTION); }; }

采纳答案by Bryan Pendleton

The Derby documentation contains an excellent set of tutorials to help you get started: http://db.apache.org/derby/docs/10.9/getstart/

Derby 文档包含一组出色的教程来帮助您入门:http: //db.apache.org/derby/docs/10.9/getstart/

回答by chandan

        Class.forName("org.apache.derby.jdbc.ClientDriver");
        String myDb = "jdbc:derby://localhost:1527/HWtrial";
        Connection DBconn = DriverManager.getConnection(myDb, "","");
         Statement st=DBconn.createStatement();
         ResultSet rs=st.executeQuery("select * from student");
         while(rs.next)
          {
            out.println(rs.getString(1));
          }|