Java School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a Java Expert!

Join 300,475 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,739 people online right now. Registration is fast and FREE... Join Now!




connecting dbase

 

connecting dbase

n.srinivasarao86

24 Dec, 2008 - 05:26 AM
Post #1

New D.I.C Head
*

Joined: 24 Dec, 2008
Posts: 4

This is my code and i placed it in WEB-INF/classes/SQLBean/DbBean.java,Dbbean.class
CODE
package SQLBean;
import java.sql.*;  
import java.io.*;  
public class DbBean
{

  private Connection dbCon;

  public DbBean()
  {  
       super();        
  }

  public boolean connect() throws ClassNotFoundException,SQLException
  {
          Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
          dbCon = DriverManager.getConnection("Jdbc:Odbc:library","jairam","ray");
          return true;
  }
  public void close() throws SQLException
  {
        dbCon.close();
  }

  public ResultSet execSQL(String sql) throws SQLException
  {
       Statement s = dbCon.createStatement();
       ResultSet r = s.executeQuery(sql);
       return (r == null) ? null : r;
}

  public int updateSQL(String sql) throws SQLException
  {                    
       Statement s = dbCon.createStatement();
       int r = s.executeUpdate(sql);
       return (r == 0) ? 0 : r;
  }

}
    
And this is JSP code and i M trying to call the connection

<%@ page language="Java" import="java.sql.*" %>  

<jsp:useBean id="db" scope="page" class="SQLBean.DbBean" />

<jsp:setProperty name="db" property="*" />

<%!  
         ResultSet rs = null;
         String name="";
          
%>

<center>  
<h2> Results from </h2>  
<hr>  
<br><br>  
<table>

<%
   db.connect();
try
{
   rs = db.execSQL("select * from addbook");
}
        catch(Exception ex)
        {
            out.println("Error"+ex.getMessage());
        }
%>
<%
while(rs.next())
  {%>
      <%=rs.getString("name")%>
<% }
%>
<br>
<%
db.close();
%>




***added code tags***
--jjsaw5

User is offlineProfile CardPM
+Quote Post


ayman_mastermind

RE: Connecting Dbase

24 Dec, 2008 - 07:43 AM
Post #2

human.setType("geek");
Group Icon

Joined: 12 Dec, 2008
Posts: 1,807



Thanked: 92 times
Dream Kudos: 525
My Contributions
so what is the problem you are facing? can you please elaborate more?
User is offlineProfile CardPM
+Quote Post

mostyfriedman

RE: Connecting Dbase

24 Dec, 2008 - 07:48 AM
Post #3

Striving Student
Group Icon

Joined: 24 Oct, 2008
Posts: 3,148



Thanked: 355 times
Dream Kudos: 600
Expert In: Learning

My Contributions
can you also place your code between code tags


This post has been edited by mostyfriedman: 24 Dec, 2008 - 07:49 AM
User is offlineProfile CardPM
+Quote Post

jjsaw5

RE: Connecting Dbase

24 Dec, 2008 - 07:48 AM
Post #4

I must break you
Group Icon

Joined: 4 Jan, 2008
Posts: 2,656



Thanked: 25 times
Dream Kudos: 125
My Contributions
You need to provide us with more information. Error messages are a good start.


code.gif
User is offlineProfile CardPM
+Quote Post

janotte

RE: Connecting Dbase

27 Dec, 2008 - 03:19 AM
Post #5

code > sword
Group Icon

Joined: 28 Sep, 2006
Posts: 2,157



Thanked: 152 times
Expert In: C/C++

My Contributions
This seems to be a duplicate (in different words) of this post:
http://www.dreamincode.net/forums/showtopic78150.htm

Probably be a clarification if the two threads were merged.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/8/09 03:03AM

Live Java Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month