连接到oracle数据库

时间:2015-12-12 15:09:50

标签: java sql netbeans ide connection

嗨,我对java足够新,我正在尝试创建从它到我的sql数据库的连接。使用Netbeans我设法很容易建立连接。问题是当我尝试使用我的代码连接时,我找不到驱动程序。我的东西有问题吗?

 //function to execute the insert update delete query
  public void theQuery(String query){
      Connection con = null;
      Statement st = null;
      try{
          con = DriverManager.getConnection("jdbc:oracle:thin:@redwood.ict.ad.dit.ie:1521:pdb12c.ict.ad.dit.ie", "eocribin","");
          st = con.createStatement();
          st.executeUpdate(query);
          JOptionPane.showMessageDialog(null,"Query Executed");
      }catch(Exception ex){
          JOptionPane.showMessageDialog(null,ex.getMessage());
      }
  }

1 个答案:

答案 0 :(得分:1)

您必须将oracle瘦驱动程序添加到项目库中,然后重新启动IDE以注意更改。运行此代码时,请确保oracle的服务器正在运行。还要检查用户名和密码。

在您的代码中使用Oracle瘦驱动程序时,netbeans中的Java持久性是一个更好的选择。因为它节省了大量的打字和录音时间。 JPA(Java Persistence API)允许您从菜单中轻松添加oracle的瘦驱动程序,并减少大部分时间。它用于企业应用程序。您应该尝试这个,并在以下网站上观看其教程。

这些被称为JPA教程。 http://www.programming-simplified.com