Results 1 to 2 of 2
  1. #1
    austinsmiles is offline Member
    Join Date
    Feb 2008
    Posts
    1
    Rep Power
    0

    Default Plz help ... retreiving data from an access database table....

    i think there is some problem with the execute query statement.......
    plz help...




    import java.sql.*;
    import java.io.*;

    public class new2
    {
    public static void main(String args[])
    {
    if(args.length!=1)
    {
    System.out.println("syntax:give filename");
    return;
    }
    java.sql.Connection conn = null;
    try
    {
    conn=AccessJDBCUtil.getAccessDBConnection(args[0]);
    Statement stmt = conn.createStatement();
    ResultSet rs=null;
    //stmt.execute(args[1]);
    rs=stmt.executeQuery("select name2 from table1 where name1=derik");
    //outputResultSet(rs);
    stmt.close();
    }
    catch(SQLException s)
    {
    System.out.println(s);
    }
    finally
    {
    if(conn != null)
    {
    try
    {
    conn.close();
    }
    catch(SQLException ignore) {}
    }
    }

    }
    /*private static void outputResultSet(ResultSet rs) throws SQLException
    {
    ResultSetMetaData rsMetaData=rs.getMetaData();
    int numberofcolumns=rsMetaData.getColumnCount();
    while(rs.next())
    {
    for(int i=1; i<(numberofcolumns+1); i++)
    System.out.print(rs.getString(i) + " ");
    System.out.println();
    }
    rs.close();
    }*/
    }

  2. #2
    jelly's Avatar
    jelly is offline Member
    Join Date
    Jan 2008
    Location
    Somerset, UK
    Posts
    46
    Rep Power
    0

    Default

    Assuming name2 is declared as varchar it will require string to be passed in the where clause, try:

    Java Code:
    rs=stmt.executeQuery("select name2 from table1 where name1='derik' ");
    If that doesn't work then please post what the failure is that you are getting
    -- Hope that helps

Similar Threads

  1. Upload excel data to access database
    By ravikumar.achi in forum New To Java
    Replies: 20
    Last Post: 01-19-2012, 11:30 AM
  2. Replies: 0
    Last Post: 03-29-2008, 03:36 PM
  3. Replies: 0
    Last Post: 02-09-2008, 08:31 PM
  4. Replies: 0
    Last Post: 02-09-2008, 08:22 PM
  5. Replies: 1
    Last Post: 08-07-2007, 07:51 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •