Access database query data in Java SCriptlet

Question:
Creating a web page and plotting points on the page:
1) Database query results in decimal values latitude and longitude.
2) Perform calculations on lati. & long. in a <% java scriptlet %>
I don't know how to pass the data back and forth between the
java server page and the java scriplet.
After the calculation translates the latitude and longitude
into xpos and ypos, a data point is plotted on a map.
I tried many ways of doing it but am just guessing as
to how to pass the data.
Thanks in Advance. - John
Here is what I am trying so far .... see snippet below:
*** Query the database ***
<sql:query var="qryBio">
SELECT
DEC_LATITUDE,
DEC_LONGITUDE,
ENTRY_TIMESTAMP
FROM app.biosurvey where
</sql:query>
*** for each row retreived from the database ***
<c:forEach var="row" items="${qryBio.rows}">
<c:set var="latvar" value="${row.dec_latitude}" scope="page"/>
<c:set var="longvar" value="${row.dec_longitude} "scope="page" />
*** java code scriptlet - ***
*** convert latitude and longitude to xpos and ypos for display ***
<%
latitude = (Float)pageContext.getAttribute("latvar");
longitude = (Float)pageContext.getAttribute("longvar");
xpos = (int)Math.round(latitude);
ypos = (int)Math.round(longitude);
xpos = 1082 - xpos;
ypos = 700 + ypos;
pageContext.setAttribute("xpos", xpos);
pageContext.setAttribute("ypos", ypos);
%>
*** plot a point on the display html page overlaying the map ***
<IMG ID="Row" SRC="smallredbox.jpg" ALT="red box"
STYLE="position:absolute;
top:<%=xposMpls%> px;
left:<%=yposMpls%> px;
z-index:2">
</c:forEach>

Question:
Creating a web page and plotting points on the page:
1) Database query results in decimal values latitude and longitude.
2) Perform calculations on lati. & long. in a <% java scriptlet %>
I don't know how to pass the data back and forth between the
java server page and the java scriplet.
After the calculation translates the latitude and longitude
into xpos and ypos, a data point is plotted on a map.
I tried many ways of doing it but am just guessing as
to how to pass the data.
Thanks in Advance. - John
Here is what I am trying so far .... see snippet below:
*** Query the database ***
<sql:query var="qryBio">
SELECT
DEC_LATITUDE,
DEC_LONGITUDE,
ENTRY_TIMESTAMP
FROM app.biosurvey where
</sql:query>
*** for each row retreived from the database ***
<c:forEach var="row" items="${qryBio.rows}">
<c:set var="latvar" value="${row.dec_latitude}" scope="page"/>
<c:set var="longvar" value="${row.dec_longitude} "scope="page" />
*** java code scriptlet - ***
*** convert latitude and longitude to xpos and ypos for display ***
<%
latitude = (Float)pageContext.getAttribute("latvar");
longitude = (Float)pageContext.getAttribute("longvar");
xpos = (int)Math.round(latitude);
ypos = (int)Math.round(longitude);
xpos = 1082 - xpos;
ypos = 700 + ypos;
pageContext.setAttribute("xpos", xpos);
pageContext.setAttribute("ypos", ypos);
%>
*** plot a point on the display html page overlaying the map ***
<IMG ID="Row" SRC="smallredbox.jpg" ALT="red box"
STYLE="position:absolute;
top:<%=xposMpls%> px;
left:<%=yposMpls%> px;
z-index:2">
</c:forEach>

Similar Messages

  • Access database query resultset in java scriptlet

    Question:
    1) I am Creating a web page and plotting points on the page:
    2) Database query results in decimal values dec_latitude and dec_longiitude.
    3) Perform calculations on lati. & long. in a java scriptlet to create a plot position (xpos, ypos).
    4) Send the xpos and ypos back to the java server page
    5) Use <IMG and absolute positioning to plot the point at position xpos, and ypos.
    6) Repeat until all rows in the query result set have been plotted.
    I don't know how to pass the dec_latitude and dec_longitude to the java scriptlet.
    After the java scriptlet calculation translates the latitude and longitude
    into xpos and ypos, I need to pass the xpos and ypos back to the java server page so that a data point is plotted on a map at position xpos, ypos.
    I tried many ways of doing it but am just guessing as
    to how to pass the data.
    Thanks in Advance. - John
    Here is what I am trying so far .... see snippet below:
    The code below results in a runtime error.
    Am I supposed to create a java object and access that in the java scriptlet? Can the java scriptlet access the latvar and longvar created during the "<c:set var="latvar"... ?
    If not, what mechanisum do I use to access the resulting colums: dec_latitude and dec_longitude? I need the java scriptlet to convert the
    dec_latitude and dec_longitude into a display position based on the number of pixels from the TOP and LEFT (xpos, ypos). Then plot of the data point using the IMG and (xpos, ypos). This will overlay a map whose z-index is lower than the plotted data point.
    *** Query the database ***
    <sql:query var="qryBio">
    SELECT
    DEC_LATITUDE,
    DEC_LONGITUDE,
    ENTRY_TIMESTAMP
    FROM app.biosurvey where
    </sql:query>
    *** for each row retreived from the database ***
    <c:forEach var="row" items="${qryBio.rows}">
    <c:set var="latvar" value="${row.dec_latitude}" scope="page"/>
    <c:set var="longvar" value="${row.dec_longitude} "scope="page" />
    *** java code scriptlet - ***
    *** convert latitude and longitude to xpos and ypos for display ***
    <%
    latitude = (Float)pageContext.getAttribute("latvar"); <--- runtime error !!!!
    longitude = (Float)pageContext.getAttribute("longvar");
    xpos = (int)Math.round(latitude);
    ypos = (int)Math.round(longitude);
    xpos = 1082 - xpos;
    ypos = 700 + ypos;
    pageContext.setAttribute("xpos", xpos);
    pageContext.setAttribute("ypos", ypos);
    %>
    *** plot a point on the display html page overlaying the map ***
    <IMG ID="Row" SRC="smallredbox.jpg" ALT="red box"
    STYLE="position:absolute;
    top:<%=xpos%> px;
    left:<%=ypos%> px;
    z-index:2">
    </c:forEach>

    Thanks
    I still get a runtime error: I translated the code you gave to code below .... which I think is equivalent. See Below: I'm still learning about this stuff so I may not have not translated this properly. Do
    you see what I am doing wrong?
    Best Regards,
    - John
    %@ page language="java" contentType="text/html;
    charset=ISO-8859-1"%>
    <%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql"%>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
    <%@ page import="java.lang.Math"%>
    <sql:setDataSource dataSource="jdbc/SampleDB" />
    <c:set var="genus_name" value="${param.genus_name}" />
    <c:set var="species_name" value="${param.species_name}" />
    <c:set var="species_common_name" value="${param.species_common_name}" />
    <c:set var="dd_sighted" value="${param.dd_sighted}" />
    <c:set var="mm_sighted" value="${param.mm_sighted}" />
    <c:set var="yyyy_sighted" value="${param.yyyy_sighted}" />
    <c:set var="species_state" value="${param.species_state}" />
    <c:set var="species_county" value="${param.species_county}" />
    <c:set var="species_country" value="${param.species_country}" />
    <c:set var="dec_latitude" value="${param.dec_latitude}" />
    <c:set var="dec_longitude" value="${param.dec_longitude}" />
    <c:set var="notes" value="${param.notes}" />
    <c:set var="person_first_name" value="${param.person_first_name}" />
    <c:set var="person_last_name" value="${param.person_last_name}" />
    <c:set var="person_street" value="${param.person_street}" />
    <c:set var="person_city" value="${param.person_city}" />
    <c:set var="person_state" value="${param.person_state}" />
    <c:set var="person_zip" value="${param.person_zip}" />
    <c:set var="person_country" value="${param.person_country}" />
    <c:set var="person_email" value="${param.person_email}" />
    <h2>Species Sightings:</h2>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>Breckenridge Citizen Bio-Survey Selective Output Page</title>
    </head>
    <body>
    Izaak Walton League of America
    <h1>Breckenridge Citizen Bio-Survey Selective Output</h1>
    <HR>
    <c:if test="${param.action == 'Submit'}">
    <%int xpos = 0;
         int ypos = 0;
         float latitude = 0.0F;
         float longitude = 0.0F;
         float latitudeMpls = 45.06F;
         float longitudeMpls = -93.14F;                    int xposMpls = 1205 - (int) Math.round(latitudeMpls);
         int yposMpls = 735 + (int) Math.round(longitudeMpls);
    %>
    <IMG SRC="minnesota_1990.jpg" ALT="minesota map" style="z-index:1;"> <----- THIS WORKS FINE
    <IMG ID="Row" SRC="smallredbox.jpg" ALT="red box"
    STYLE="position:absolute;
    top:<%=xposMpls%> px;
    left:<%=yposMpls%> px;
    z-index:2"> <----- THIS WORKS FINE FOR HARDCODED MPLS XPOS AND YPOS
    <sql:query var="qryBio">
    SELECT
    PERSON_FIRST_NAME,
    PERSON_LAST_NAME,
    GENUS_NAME,
    SPECIES_NAME,
    SPECIES_COMMON_NAME,
    SPECIES_COUNTY,
    SPECIES_STATE,
    SPECIES_COUNTRY,
    DD_SIGHTED,
    MM_SIGHTED,
    YYYY_SIGHTED,
    DEC_LATITUDE,
    DEC_LONGITUDE,
    NOTES,
    ENTRY_TIMESTAMP
    FROM app.biosurvey where
    genus_name like rtrim(upper('${genus_name}')) AND
    species_name like rtrim(upper('${species_name}')) AND
    species_common_name like rtrim(upper
    ('${species_common_name}')) AND
    species_state like rtrim(upper('${species_state}')) AND
    species_county like rtrim(upper('${species_county}')) AND
    species_country like rtrim(upper('${species_country}')) AND
    person_first_name like rtrim(upper('${person_first_name}')) AND
    person_last_name like rtrim(upper('${person_last_name}')) AND
    person_email like rtrim(upper('${person_email}'))
    </sql:query>
    <c:forEach var="row" items="${qryBio.rows}">
    <--- THE LINE ABOVE WORKS FINE --->
    <c:set var="latvar" value="${row.dec_latitude}" scope="page" />
    <c:set var="longvar" value="${row.dec_longitude} " scope="page" />
    <%
    latitude =
    Float.parseFloat((String)pageContext.getAttribute("latvar"));
    <--- RUNTIME ERROR OCCURS HERE --- SEE LINE ABOVE --->
    longitude =
    Float.parseFloat((String)pageContext.getAttribute("longvar"));
    xpos = (int) Math.round(latitude);
    ypos = (int) Math.round(longitude);
    xpos = 1082 - xpos;
    ypos = 700 + ypos;
    request.setAttribute("xpos",new Integer(xpos));
    request.setAttribute("ypos",new Integer(ypos));
    %>
    IIMG ID="Row" SRC="smallredbox.jpg" ALT="red box"
    STYLE="position:absolute;
    top:<%=xpos%> px;
    left:<%=ypos%> px;
    z-index:2">
    <--- THIS (ABOVE) WORKS FINE WITH CORRECT VALUES FOR XPOS AND YPOS WHEN RUNTIME ERROR DOES NOT OCCUR --->
    </c:forEach>
    </c:if>

  • Access database query import

    I have some queries stored in databases from MS Access which I am trying to import into DIAdem.  I use the open with option for the database to select the query I wish to load and then chose selective opening to grab the columns of data I really want.  It appears to import the data but only the first 27890 entries - the total is approx 750,000.  Why is only about 27890 entries being imported?

    Hi Jim,
    No, I am not sure why you are experiencing this difference in load behavior.  We tried to replicate your situation here and were able to successfully load either by selecting the whole table or specific columns within that table:
    ACCESS Table with 7 columns, each column with 560 000 values
    Tested on both a DIAdem 9.1 SP2c computer and a DIAdem 10.1 SP1 computer (clean installs)
    Result in DIAdem:
    7 channels, each channel with 560 000 values if I load the table complete
    3 channels, each channel with 560 000 values if I load selected channels
    The first step is for us to reproduce your symptoms.  Would it be possible for you to post your Access database on our ftp.ni.com/incoming server?
    How much RAM do you have on your computer?
    Brad Turpin
    DIAdem Product Support Engineer
    National Instruments

  • Access Database Query

    I am running a query on an access database, but am getting some strange results. The problem might be access and not Visual studio though.
    Here is the core of the problem:
    If I run the following query, I get exactly what I want
    SELECT ID, Question, Solved, Date_Created, Date_Last_Edit, Date_Closed
    FROM(
    SELECT F.ID AS Ident, Count(F.ID) AS Num
    FROM(
    SELECT Keywords, ID, Question, Solved, Date_Created, Date_Last_Edit, Date_Closed
    FROM(
    SELECT ID, Solved, Date_Created, Date_Closed, Date_Last_Edit, Question, Model, Keywords.Value AS Y FROM Questions) AS X INNER JOIN Keywords ON X.Y =Keywords.ID
    Where Keywords = "Back" ) As F
    Group By F.ID
    HAVING (((Count(F.ID)) =1)))
    As T Inner Join Questions
    On T.Ident = Questions.ID
    But, if I change
    Where Keywords = "Back"
    to
    Where Keywords Like "*Ba*"
    I get nothing from my query. No errors, just no data.
    The strange thing is, if I output my query to a message box, and copy and paste it into access and run the query, it runs just fine. I've double checked all the syntax and I don't get a syntax error back from the code anyway.

    Hi Mynamewasused,
    Thank you for posting in MSDN forum.
    Since this forum is to discuss: Visual Studio WPF/SL Designer, Visual Studio Guidance Automation
    Toolkit, Developer Documentation and Help System, and Visual Studio Editor.
    To help you find the correct forum support this issue, could you please tell me if you running a query on an access database with ADO.NET?
    Best Regards,
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • How to create a ms-access database at runtime using java

    hi, this is ravi kiran,
    i have a situation where i need to create a new ms-access database with one table in it at runtime(when user clicks on some button).
    i have been searching many sites to know how to do this in java, but i didnot find any thing useful.
    plz tell me how to do this in java.
    plz help me, its urgent
    thanx in advance.

    Here's how I did it. Research does help, but sometimes looking at others code does too... You do have to have a dummy file that you made with access though. You can't just make a file file.mdb (it will be corrupt)
         public void createDatabase(String database) throws SQLException{
              try{
                   // This file needs to have been created with MS Access
                   File dbfile = new File(this.dataBaseDir + "dummy.mdb");
                   // This is the new database file being made
                   File newFile = new File(this.dataBaseDir + database + ".mdb");
                   // Copy all bytes from dummy file to new DB file.
                   FileInputStream instream = new FileInputStream(dbfile);
                   FileOutputStream ostream = new FileOutputStream(newFile);
                   int numBytes = instream.available();
                   byte inBytes[] = new byte[numBytes];
                   instream.read(inBytes, 0, numBytes);
                   ostream.write(inBytes, 0, numBytes);
              catch(FileNotFoundException e) { e.printStackTrace();}
              catch(IOException e) { e.printStackTrace();}
              if(DEBUG) System.out.println("creating the " + database + " database");
         }

  • How to access MS ACCESS database from Solaris running Java application

    Hello I have a reqmt
    My Java application is running on Weblogic server on Solaris 2.7 and now I want to connect to MS Access database running on Win NT.
    How do I do that??
    Any help is appreciated
    Thanks
    Suresh

    You have to use a proxy server and client.
    You can search for commercial solutions via the sun jdbc site or use RmiJdbc at http://www.objectweb.org/

  • How to know MS Access Database is down through Java

    How i would know whether MS Access DataBase is down?
    Is there any specific code for it in Java
    Need a quick reply

    How i would know whether MS Access DataBase is down?"down"? If the file system on which it's running is unavailable, that's the best you can do. If you can't connect, it's "down".
    Is there any specific code for it in JavaNo. Doesn't sound very platform-independent.
    Need a quick replyFast enough?
    %

  • Why is the Microsoft Office Access Database Engine data source looking for a workgroup information file?

    While trying to import to MSSQL2012 from SSDT using the wizard from an Access 2013 DB (.accdb) which is password protected, I get the following error with the username blank and the password field correctly populated: 
    Cannot start your application. The workgroup information file is missing or opened exclusively by another user. (MicrosoftOffice Access Database Engine)
    But according to this link:
    http://office.microsoft.com/en-us/access-help/what-happened-to-user-level-security-HA010342116.aspx
    MSA10 and beyond shouldn't need workgroup information files, although it's not clear to me if they are
    created/used or not.
    I can point the wizard to some local version of system.mdw at Advanced -> All -> Jet OLEDB:System Database, and then the error becomes:
    Not a valid account name or password. (Microsoft Office Access Database Engine)
    for any username I can think of.
    Questions:
    1.  Why does this data source insist on looking for a workgroup information file even though user-level security should be disabled?
    2.  Why does the Open dialog box for the Microsoft Access Database Engine have *.mdb as the only selectable filetype?
    3.  How can I get around these errors for an .accdb that is password protected?
    Thanks!

    Hi JordanPG,
    To connect to Access 2007 or later database, we need the Microsoft ACE 12.0 OLE DB driver. SQL Server only installs the Microsoft Jet 4.0 OLE DB driver which can be used to connect to Access 2003 or earlier database. Besides, the Microsoft Jet 4.0 OLE DB
    driver only has 32-bit version, but the Microsoft ACE 12.0 OLE DB driver has both 32-bit and 64-bit version. However, the 32-bit and 64-bit Microsoft ACE 12.0 OLE DB drivers cannot be installed on a single server.
    According to your description, you can use the 64-bit SQL Server Import and Export Wizard to load data from the Access database, so the 64-bit Microsoft ACE 12.0 OLE DB driver is installed on your computer. Since the BIDS/SSDT is a 32-bit application, the
    64-bit Microsoft ACE 12.0 OLE DB Provider is not visible in BIDS/SSDT. So, when you said that you select “Microsoft Access (Microsoft Access Database Engine)" in the SQL Server Import and Export Wizard (it is actually the 32-bit version) started by the SSDT,
    I think it should be “Microsoft Access (Microsoft Jet Database Engine)”. Because the Microsoft Jet 4.0 OLE DB driver only supports Access 2003 or earlier format, it threw the error “Test connection failed because of an error in initializing provider. Unrecognized
    database format 'C:\myDB.accdb'”.
    In this situation, you have two approaches to avoid this issue:
    Launch the SQL Server Import and Export Wizard (64-bit), and select “Save SSIS Package” to “File System” on the “Save and Run Package” page. Then, the package will be saved to a specified directory. After that, you can add this existing package to a SSIS
    project. The status of the corresponding OLE DB Connection Manager should be Work Offline, or the OLE DB Source will throw an error about 32-bit driver if the Connection Manager is not in Work Offline status, you can ignore that and the package can run successfully
    in SSDT as long as the project is set to run in 64-bit runtime mode.
    However, for the SSDT 2012 integrated with Visual Studio 2012, the 64-bit runtime mode is disabled. In this situation, to run the package in SSDT, you have to uninstall the 64-bit Microsoft ACE 12.0 OLE DB drivers and install the 32-bit one. Here is the
    download link:
    http://www.microsoft.com/en-in/download/details.aspx?id=13255 
    Regards,
    Mike Yin
    TechNet Community Support

  • Trying to display results from access database query on a JSP

    Seem to be having real difficulty with this one, i keep getting a null pointer exception :(. Wondered if anyone could point me to any examples of displaying the results on jsp. The database is connected, as i can display the query on netbeans, but just not on a jsp.

    I think it would be good if we had a section in these forums for pre-canned answers to the same questions that come up again and again. It would save time.
    Here is a rough outline for using JSP:
    * Read a JSP book.
    * The JSP page (View in MVC) should get all the data it needs to display from a useBean and/or request.getAttribute().
    * The JSP page should not have any business logic. Its purpose is to display data only (and have some submit buttons such as 'update').
    You can do some basic client side validation using javascript if you want. Because there is no business logic in it, you can easily debug
    your code in the servlet or business logic. You can't set breakpoints in JSP and examine data easily.
    * When you click the submit button, all data from <input type="text" tags, etc is put into request scope via name/value pairs.
    * Submit the JSP page <form tag to a servlet (Control in MVC).
    * The servlet reads the name/value pairs of data from the JSP page via request.getParameter()
    * The servlet should then instansiate a business object (Model in MVC), passing the data it got from the page to the business logic.
    Example: ProcessPage processPage();
    if(request.getParameter("updateButtonClicked"))
    processPage.updateData(data from the jsp page)
    * The business logic should instansiate a separate database object (DAO) to get data to/from the database. Business logic should not have sql in it.
    Business logic should not generate html. Business logic should not have request objects in it.
    * The business logic should return data to the servlet that in turn will put it in request scope via request.setAttribute() so the JSP page can draw itself.
    * The servlet should then call up the approprate JSP page.

  • Are there any APIs to access user personalization data from java

    Hi gurus,
    We want to access personalization data for a user from java using API. This includes user mapping also.
    If you are aware of any api please let me know.
    Thanks in advance.
    Regards,
      Pratik Thakkar

    Hi Pratik,
    You can also retrieve a system object and get the user mapping for the system:
    Hashtable env = new Hashtable();
    env.put(Context.INITIAL_CONTEXT_FACTORY,IPcdContext.PCD_INITIAL_CONTEXT_FACTORY);
    env.put(Context.SECURITY_PRINCIPAL, request.getUser());
    env.put(Constants.REQUESTED_ASPECT, PcmConstants.ASPECT_SEMANTICS);
    iCtx = new InitialContext(env);
    ISystem pcdSys =(ISystem)iCtx.lookup(sysId);
    ISystemUserMappingData um = pcdSys.getUserMappingData(request.getUser());
    From this object you can get the user, password and other properties.
    As for personalized values of iView attributes, you can an environmental value before create the initial context to indicate to return personalized value, as follows:
    env.put(IPcdContext.PCD_PERSONALIZATION_PRINCIPAL, request.getUser());
    Hope this helps.
    Daniel

  • Best Practice on querying Data from Database

    Hello and I was wondering what is the preferred and best practice for querying data from an SQL database inside a JSP page. Is it using the JSTL library or another method? Thanks

    It depends on the size of the application really.
    The "correct and preferred" approach in a large MVC app would be to have a seperate class that does all the database access, retrieving the data into java objects.
    Check out [url http://java.sun.com/blueprints/corej2eepatterns/Patterns/DataAccessObject.html] DAO pattern
    You then "save" the data into request/session attributes, and forward to a jsp page to render the result.
    Most approaches recommend a separation between JSP (the view) and SQL code.
    The JSTL sql tags are provided more for "quick and dirty" code applicable in small applications, or for fast prototyping. That approach is not really robust for large scale applications.
    Cheers,
    evnafets

  • Help on using 2 MS Access databases at the same time

    I have a problem... see what basically I am trying to do is search for a string in the database 'cache'. if found the second colume is retured to the user as the output. but if not found in that 'cache' then it serches another datbase 'server' and when the req string is found there it has to return the 2nd column to the user but also add this new row in to the 'cache' database.
    The source that I am trying for that is as follows.
    import java.sql.*;
    public class localdemo {
    public static void main(String[] args) {
    String s,r;
    String x;
    String t=args[0];
    try {
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
    // Test with MS Access database (ODBC data source)
    String url = "jdbc:odbc:Servers";
    String urlc = "jdbc:odbc:cache";
    java.sql.Connection c = DriverManager.getConnection(url,"chetan", "mavric1");
    java.sql.Connection c1 = DriverManager.getConnection(urlc,"chetan", "mavric1");
    java.sql.Statement st = c.createStatement();
    java.sql.Statement stc = c1.createStatement();
    java.sql.ResultSet rs = st.executeQuery("select * from server");
    java.sql.ResultSet rsc = stc.executeQuery("select * from cache");
    //java.sql.ResultSetMetaData md = rs.getMetaData();
    //java.sql.ResultSetMetaData mdc = rsc.getMetaData();
              while(rsc.next()) {
    s=rsc.getString(1);
    if(s.equals(t))
    System.out.print(rsc.getString(2));
         System.exit(1);
    System.out.println("\nDNS Entry not found in the Cache...");
    System.out.println("\nMoving to the Main server database..\n");
    while(rs.next()) {
    r=rs.getString(1);
    if(r.equals(t))
         System.out.print(rs.getString(2));
    String query = "insert into cache(server,ip) values(t,rs.getString(2))";                                                                                     
    int rows = stc.executeUpdate(query);
         stc.close();
    rs.close();
    rsc.close();
    } catch(Exception e) {
    e.printStackTrace();
    it gives me an error
    java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Undefined function 'rs.getString' in express
    ion.
    at sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown Source)
    at sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source)
    at sun.jdbc.odbc.JdbcOdbc.SQLExecDirect(Unknown Source)
    at sun.jdbc.odbc.JdbcOdbcStatement.execute(Unknown Source)
    at sun.jdbc.odbc.JdbcOdbcStatement.executeUpdate(Unknown Source)
    at localdemo.main(localdemo.java:46)
    PLease help
    regards
    Chetan

    Hi ,
    It's always better to acquire resources when ever they are
    going to be used.
    So please change the code as shown below.
    import java.sql.*;
    public class localdemo {
    public static void main(String[] args) {
    String s,r;
    String x;
    String t=args[0];
    try {
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
    // Test with MS Access database (ODBC data source)
    String url = "jdbc:odbc:Servers";
    String urlc = "jdbc:odbc:cache";
    java.sql.Connection c = null;
    java.sql.Connection c1 = DriverManager.getConnection(urlc,"chetan", "mavric1");
    java.sql.Statement st = null;
    java.sql.Statement stc = c1.createStatement();
    java.sql.ResultSet rs = null;
    java.sql.ResultSet rsc = stc.executeQuery("select * from cache");
    //java.sql.ResultSetMetaData md = rs.getMetaData();
    //java.sql.ResultSetMetaData mdc = rsc.getMetaData();
    while(rsc.next()) {
    s=rsc.getString(1);
    if(s.equals(t))
    System.out.print(rsc.getString(2));
    System.exit(1);
    rsc.close();
    System.out.println("\nDNS Entry not found in the Cache...");
    System.out.println("\nMoving to the Main server database..\n");
    c= DriverManager.getConnection(url,"chetan", "mavric1");;
    st=c.createStatement();
    rs=st.executeQuery("select * from server");
    while(rs.next()) {
    r=rs.getString(1);
    if(r.equals(t))
    System.out.print(rs.getString(2));
    String query = "insert into cache(server,ip) values(t,rs.getString(2))";
    int rows = stc.executeUpdate(query);
    stc.close();
    rs.close();
    } catch(Exception e) {
    e.printStackTrace();
    Hope this helps.
    Good Luck.
    Gayam.Srinivasa Reddy
    Developer Technical Support
    Sun Micro Sysytems
    http://www.sun.com/developers/support/

  • Replication of MS Access database

    Is this possible to replicate an MS Access database (.mdb) file using Java?.
    I want to do this either in JSP or Servlet.
    Please provide any resource links.
    This is quite urgent.
    Thanks in advance.

    please don't cross-post
    http://forum.java.sun.com/thread.jsp?forum=54&thread=344531
    do you want to make a copy of an Access database? Or do you want to synchronize two (or more) databases? Either way, if your options are JSP or Servlet (pretty much the same things, really), use a straight servlet, no need to throw in HTML. As for the actual mechanics of your replication, it depends on what you want to do.
    Lee

  • Java, access database( mdb) and java.sql.date

    I having a problem querying my access database with user specified date the code is as follows
    //get results of income from database with respectto dates
         //so u first create the sql.date instances
         private void getResults(){
         String text1=from.getText();//text input is like this 01-01-2005
              String text2=to.getText();
         Date d1=new Date(Integer.parseInt(text1.substring(6)),Integer.parseInt(text1.substring(3,5)),Integer.parseInt(text1.substring(0,2)));
         JOptionPane.showMessageDialog(this,d1.toString());//traces date with 1900 added to year and 1 added to month
         try{
              //custom class DataSource used to connect to database
              Connection conn=DataSource.getConnection("RealFotoInc");
              PreparedStatement ps=conn.prepareStatement("select * from Members where date=?");
              ps.setDate(1,d1);
              ResultSet rs=ps.executeQuery();
              while(rs.next()){
                   System.out.println("going");
                   System.out.println("trial"+rs.getString(3));
         }catch(Exception se){
              JOptionPane.showMessageDialog(this,se);
         }and it prints out nothing I dont know what is wrong

    Whoever put that comment in there about "1900" and so on knew what had to be done. That "Date" class must be "java.sql.Date"; go and read the API documentation of that constructor you are using there. Then adjust the parameters you are passing to it accordingly.

  • How to insert date into ms access database using sql query in servlet

    sir all thing is working well now only tell me how we can insert date into ms access database which is input by user .
    insert into db2(bookname,studentname,date) values('"+bname+"','"+sname+"',date_format)";{code}
    or either the system date is inserted with query .
      plz help me
    thanx                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    bhavishya wrote:
    sir all thing is working well now only tell me how we can insert date into ms access database which is input by user .
    insert into db2(bookname,studentname,date) values('"+bname+"','"+sname+"',date_format)";{code}
    or either the system date is inserted with query .
    plz help me
    thanxAnd that SQL statement is another reason to use PreparedStatement. I assume bname and sname are input from some form? Well, if that's the case, simply inserting them into SQL by simple String concatenation is just begging for all sorts of problems. What if there is an apostrophe in the entry? Broken Statement. Worse, it's a wide open invitation to an SQL Injection attack.

Maybe you are looking for