Cannot connect and run query for Access database

Hi,
I have a html file and a servlet file which contains code to connect to a database. I also have a sales database with customer table along with other tables in Access. I have created a DSN in Windows named sales which connects to the sales database. Now, when I am running the html form, the servlet does not run the query "Select * from Customer". It seems it cannot make any connection to the database.
Any help is appreciated. I am very new to JDBC technology. Thanks.
HTML FORM CODE:
<html>
<head><title>Sales</title></head>
<body>
<form action="http://localhost:8100/servlet/SalesServlet" method=POST>
<strong>Select:</strong>
<textarea cols=50 rows=8 name=select></textarea><p>
<input type=submit value="Query">
<input type=reset>
</form></body></html>
SALESSERVLET CODE:
//Copyright (c) 2000, Art Gittleman
//This example is provided WITHOUT ANY WARRANTY either expressed or implied.
/* Queries the Sales database. Needs to be modified
* to use metadata to correctly output the result set.
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
import sun.jdbc.odbc.JdbcOdbcDriver;
public class SalesServlet extends HttpServlet {
Connection con;
Statement stmt;
public void init(ServletConfig sc) throws ServletException {
super.init(sc);
try{
new JdbcOdbcDriver();
String url = "jdbc:odbc:Sales";
String user = "";
String password = "";
con = DriverManager.getConnection(url, user, password);
stmt = con.createStatement();
}catch (Exception e) {
e.printStackTrace();
System.exit(1);
public void doGet(HttpServletRequest req,
HttpServletResponse resp)
throws ServletException, IOException {
resp.setContentType("text/html");
PrintWriter out = resp.getWriter();
try{
String query = req.getParameter("select");
ResultSet rs = stmt.executeQuery(query);
ResultSetMetaData rsMetaData = rs.getMetaData();
int cols = rsMetaData.getColumnCount();
while(rs.next()) {
String s = "";
for(int i=1; i<=cols; i++)
s += rs.getString(i) + ' ';
s += "<br>";
out.println(s);
}catch(Exception e) {
e.printStackTrace();
out.close();
public void doPost(HttpServletRequest req,
HttpServletResponse resp)
throws ServletException, IOException {
doGet(req,resp);
}

String url = "jdbc:odbc:Sales";
String user = "";
String password = "";
con = DriverManager.getConnection(url, user, password);This might be causing your problem, but not sure. Since you don't need a username or password for the ODBC connection, you can just use
con = DriverManager.getConnection(url);
The username and password aren't needed, so you can just use the above call instead. Perhaps the ODBC is trying to find a user called "" with a password "" and puking on itself, who knows... but you should post whatever exceptions or specific problems you're having that make you think you're not connecting.

Similar Messages

  • How to using sqlplus to connect and run command ?

    Hello,i have a small problem please help me
    I want to use sqlplus to connect and run command
    for example : sqlplus test/test@DB select sysdate from dual ;
    and then it will show data (sysdate) to screen
    what should i do ?
    Thanks

    kenshin19xx wrote:
    Hello,i have a small problem please help me
    I want to use sqlplus to connect and run command
    for example : sqlplus test/test@DB select sysdate from dual ;
    and then it will show data (sysdate) to screen
    what should i do ?
    Thanks
    bcm@bcm-laptop:~$ echo "select sysdate from dual ;" > now.sql
    bcm@bcm-laptop:~$ sqlplus user1/user1 @now
    SQL*Plus: Release 11.2.0.1.0 Production on Wed Dec 14 20:41:33 2011
    Copyright (c) 1982, 2009, Oracle.  All rights reserved.
    Connected to:
    Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
    SYSDATE
    2011-12-14 20:41:33

  • HT202157 Wwhen i go from cable tv to apple and click on netflix to stream, it tells me I cannot connect and tey again later. What can I do as it has been doing this for 2 weeks.

    When I go from cable tv to apple and click on netflix it tells me that it cannot connect and to try later. What is the problem, it has been happening for 2 weeks?

    Power cycle the ATV and router.

  • Ios7 "Cannot Connect to iTunes Store". When I try clicking on the "Terms and Conditions" in iCloud, it first says "Cannot Connect" and then the following mes

    Hi, I have upgraded my iphone 4s to ios7 and now when I am trying to login to app store, it says "Cannot Connect to iTunes Store". When I try clicking on the "Terms and Conditions" in iCloud, it first says "Cannot Connect" and then the following message: "Verification Failed: the certificate for this server is invalid. you might be connecting to server that is pretending to be setup.icloud.com, which could put your confidential information at risk". My wifi is working properly as I have accessed websites from safari. I reset my network settings too and even reset my password. But none of these get my iphone working.

    I'm having the same problem with the iTunes Store...it much be down :(

  • Erro while running query for a Scheduled work book

    The following error found while running query for a schedule workbook:
    ORA-12801: Error signaled in parallel query server P000
    ORA-01652: uable to extend temp segment by 14720 in tablespace SYSTEM
    ORA-27068: skgfdisp: buffer is not aligned properly
    OSD-04005: SetFilePointer() failure, unable to read it from file
    We are using discoverer 4.1.
    Any help is highly appreciated.
    null

    Candi,
    Have your DBA check for trace file and contact Oracle Support: RDBMS group to track these errors down...
    Chris
    null

  • How to make a button to stop and run a for loop?

    How to make a button to stop and run a for loop?  and if it is stopped it shall start from where i t stopped.

    Your VI has some very fundamental flaws.
    The start/stop button is outside the FOR loop, thus it will NOT get read during execution of the FOR loop, but only before the FOR loop starts. Think dataflow!
    Thus the terminal of the start/stop button belongs inside the FOR loop.
    Your FOR loop iterates 20x, which probably takes about a nanosecond. You will NOT be fast enough to reliably press the start/stop button during a specific iteration of the FOR loop.
    Your code does not "stop and run" a FOR loop (sic). The loop always spins, but executes an empty case when "Stopped". I guess that's what you actually want?
    Once you solve (2), the x indicator will contain a random value whenever you "stop".
    As soon as the 20 iterations complete, the outer while loop spin an things start over, another nanosecond later.
    Place e.g. a 500ms wait inside the FOR loop to solve this.
    Don't place terminals of indicators on top of formula nodes.
    Your formula does not produce any output, so really has no purpose.
    Use a real "stop" button to terminate the while loop (mechanical action: latch when released). Right now you are using a plain switch, which does not reset to false before the next run. This means that you need to manually reset it before running the program again.
    It is oftern useful to operate the VI in execution highlighting mode. You will immediately see that your button does not get read during execution of the FOR loop. Try it!
    LabVIEW Champion . Do more with less code and in less time .

  • Recommended Third Party Archive and Purging Software for Oracle Database (Oracle CC&B)

    Hi,
    We are currently exploring third party archive and purging software for Oracle Database specifically used by an Oracle Customer Care and Billing implementation. Our current data is growing that we think archiving and purging is a now a viable option. Thanks.
    Regards,
    Dennis

    According to the fine Oracle® Utilities Application Framework Administration Guide Chapter 17, "Archiving and Purging" is readily available to CC&B.

  • I cannot connect to an update for windows for adobe premiere elements 9 ar to change my sign-in. it gives me an error message 400 saying photo shop is unavailable. this makes the second day.

    I cannot connect to an update for windows for adobe premiere elements 9 ar to change my sign-in. it gives me an error message 400 saying photo shop is unavailable. this makes the second day.

    This is a user to user forum, not Adobe support
    Select a topic, then click I STILL NEED HELP to start Premiere Elements Online chat
    -http://helpx.adobe.com/contact.html?step=PRE

  • I need a request code for offline activation. Because i cannot connect with adobe server for online activation. But I receive "The request code is invalid." by generate answer code.

    I need a request code for offline activation. Because i cannot connect with adobe server for online activation. But I receive "The request code is invalid." by generate answer code.

    Dear Anubha,
    I hope these windows illustrate what I am facing.
    The above window shows the prompt that the software requires activation.
    The version is 8.1.0.
    This next window is the point where I select activation by phone.
    This final window shows that the "response code" is not returned.  I get an
    "Activation Number" instead.
    Steven
    On Tue, Jan 27, 2015 at 10:50 PM, Anubha Goel <[email protected]>

  • Thin driver for Access Database

    Hi Guys,
    I want to know the exact thin JBBC driver for access database,
    For oracle we have "jdbc:oracle:thin:@host:port:sid" driver, I need the similar type of driver for Access,
    Where can I find
    Thanks

    let me be a bit more descriptive..
    there's no free, publicly available type 3 or 4 driver for Access.
    However, if you want to buy one, take a look at this URL: http://industry.java.sun.com/products/jdbc/drivers .
    It'll help you identify third-party vendors who sell what you're looking for...
    Larry

  • Im using an iphone 4s with the latest firmware which is 6.1.3 but my wifi button keeps going grey how can i fix it? i rested network connections and it worked for a while and went grey again,what can i do?

    im using an iphone 4s with the latest firmware which is 6.1.3 but my wifi button keeps going grey how can i fix it? i rested network connections and it worked for a while and went grey again,what can i do?

    Have you worked through the Troubleshooting iOS and WiFi knowledge base article?  If not, see if there is info in there that might help.
    Is the WiFi greyed out on all WiFi networks or just the one?  If it does this on all then there may be a hardwaer problem that needs attention from the techs at an Apple store genius bar.
    Before that, however, try a reboot by holding both the power and home buttons until the apple logo appears and it restarts, ignoring the red slider if it appears.  That clears a lot of iOS hang ups that occur.

  • Cannot connect to BW query and MDX error

    i have few issue encountered on webi connected to SAP BI 7 and BW 3.x
    SAPBI7
    1)while select the cube/multiprovider on universe connection, i cannot see all the query availbale at BW, only show some query. but i can see all cube/multiprovider. whey?
    2)i hit database error when generate webi report from BI7.0 the error msg is "A database error occured the database text is : The MDX Querry SELECT {.....". it working fine when connect to BW 3.x.
    SAPBW 3.x
    1) i cannot see query from univese connection when connect BW 3.x, only can see cube/multiprovider. i using java connect
    SAP Java Connector 2.1.8 , SAP edge 3.1
    Please help .. thanks

    Hi,
    1)while select the cube/multiprovider on universe connection, i cannot see all the query availbale at BW, only show some query. but i can see all cube/multiprovider. whey?
    >> BW queries need to be released for external access in the Query Designer
    2)i hit database error when generate webi report from BI7.0 the error msg is "A database error occured the database text is : The MDX Querry SELECT {.....". it working fine when connect to BW 3.x.
    >>> Does the actual query that you were using work in transaction RSRT.
    SAPBW 3.x
    1) i cannot see query from univese connection when connect BW 3.x, only can see cube/multiprovider. i using java connect
    SAP Java Connector 2.1.8 , SAP edge 3.1
    >>> see above on item #1.
    Ingo

  • EA3 and EA2 - bug - cannot connect to global accounts in 10g databases

    It is not possible to connect using a global account (LDAP-authenticated) for a 10.1 or 10.2 database. It works fine with 9.2, and all such connections work fine in SQL Dev 1.2.
    The EA2 thread for this bug is at EA2 - Cannot connect LDAP-authenticated users in 10.1 and 10.2, OK in 9.2 It includes all of the other relevant details.

    I should probably add that I am able to make successful connections via sqlplus and other tools (SQL Navigator) with the users that fail to connect in SQL Developer.

  • Basic Database connection and run querry.

    Hi, I pretty new to java, So if any can help, please do.
    All i want to do is connect to a sql database and run a querry, return the results and then output them as XML.
    I have no idea where to start!
    Please Help.

    JDBC resources:
    http://java.sun.com/products/jdbc/download.html
    http://java.sun.com/docs/books/tutorial/jdbc/basics/
    http://developer.java.sun.com/developer/technicalArticles/Database/dukesbakery/
    http://developer.java.sun.com/developer/onlineTraining/Database/JDBC20Intro/JDBC20.html#JDBC209_1
    XML resources:
    http://wwws.sun.com/software/xml/
    http://java.sun.com/xml/
    http://developer.java.sun.com/developer/codesamples/xml.html
    http://developer.java.sun.com/developer/technicalArticles/xml/JavaTechandXML/
    These may give you a start.
    You can use the advanced search across the user forums or the Sun site to find many more examples and problem solutions.
    Also the google search engine is very good for searching the web for java information.
    rykk

  • So recently I have stopped using hamachi to run my server on minecraft and decided to port forward it. My friends cannot connect and it is really bugging me.

    I have an airport extreme and have airport utility version6.1. I have gone into airport utility and entered in the port 25565 into the public and private udp and tcp. i also have reseved the dchp and put in my mac adress as well as entered in the ip adress straight from the network section in preferences. In my minecraft server properties I have left the ip blank. I have used a port checker tool and it says it cannot connect to the port on tcp with 25565. I have no idea why this is happening because I entered everything in correctly. I would really appreciate it if someone were to help me.

    You will need to set your Mac up to have a static IP address on your internal network. This can be found in System Preferences>Network:
    You will want to select DHCP with manual address.

Maybe you are looking for

  • G5 Quad - No Airport Reception After Upgrade - Software Issue

    Hi, I've just installed a 'wireless upgrade kit' in my quad (yes, I know it says AASP install only but I did in anyway). Bluetooth is working fine but airport gives me no reception at all. Now, after some poking around I became pretty convinced this

  • My audio for songs all sound like chipmunks...

    I actually know what I did wrong...I just can't get it back. All audio on my computer is sped up. I uninstalled Microsoft Plus! Digital Media Edition, and did not know this would happen. I tried Restoring my computer to earlier dates but it will not

  • Comparing count of one table with another

    Hi, I want to compare the number of rows in three tables with the number of rows in another table and see if they are equal Here is what I have so far: SELECT decode(the_count,100,1,0) from (select sum(num_rows) as the_count from user_tables where ta

  • 7.5 Standby apply log issue - Cold backup of standby

    We are in the process of migrating to 7.8 from 7.5 and have a 7.5 standby. Needed to test the time is takes to backup from the standby once we go-live on the 7.8 64bit server. Logs have been applied to the 7.5 standby for more than a month just fine

  • Tutorial Video problems

    I'm having a problem with the video with a spry example located here and is also on the tutorial dvd that comes with the Web Premium hard copy. I have done the tutorial over and over. I even found a written version of it on adobe.com and I still don'