Database access using servlet MIDlet communication

Hi all,
Could anyone please help me?
I have written a MIDlet connecting to the TOMCAT web server and invokes a Servlet. The Servlet then fetches data (list of names) from MS Sql Server and returns to the MIDlet. Then the MIDlet displays the names in a ChoiceGroup . And MIDlet invokes another servlet to update
So far everything works well.
The hard part with this solution is
1. Servlet has to send the result as delimited strings (with :)
2. The midlet has to parse the servlet data and extracts the values. this all done through the code only. no routines i used
3. the url has to have %20 for space otherwise the Connector.open(url) method throws error.
Can anyone suggest better solutions for this. perhaps easy?
Regards,
//Selva

Ok, so this is the code i use in the MIDlet to post the two parameters, but i can't get them in the servlet. What's wrong?
HttpConnection c=(HttpConnection)Connector.open(serverURL);
System.out.println("Connecting");
c.setRequestMethod(HttpConnection.POST);
c.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
dos=c.openDataOutputStream();
dos.writeUTF("user=" + userName);
dos.writeUTF("&password=" + password);
dos.writeUTF("\r\n");
dos.flush();

Similar Messages

  • Displaying results from a database query using servlets

    I have this HTML form where users can search a MS Access database by entering a combination of EmployeeID, First name or last name. This form invokes a Java Servlet which searches the database and displays the results as an HTML page. I am giving the user the choice of displaying 3, 5 or 10 results per page. I want to know how to do that using servlets. If a particular search results in 20 results, the results should be displayed in sets of 3, 5 or 10 depending on the user's choice. If the user makes a choice of 5 results per page then 4 pages should be displayed with a "next" and "previous" button on each page. I want to know how this can be done.

    Arun,
    I'm not sure how to do this using JSP as I have not worked on JSP.
    But I can give you a hint on how to do this within normal java class as I've used this in my current project.
    In your core class/bean that generates the entire resultset, you need to run a loop that will scan through the desired number of records in the resultset.
    To do this, you have to have skip and max parameter in your URL.
    Somthing like http://server.com/myservlet?skip=0&max=10 to display first 10 records, http://server.com/myservlet?skip=10&max=10 to display next 10 records. The <next>parameter would be fed in by the user by a simple form in your web-page. If you need to hold this <max-num-of-recs-per-page> param, you can store it in a cookie (since this is nothing crucial piece of info, don't need to use session obj etc...cookie will do) and get the value each time you display the resultset.
    So, essentially, suppose you are at the first page and you wish to show 10 recs at a time. The link for "Next" button would be http://server.com/myservlet?skip=10&max=10
    when at the second page, you'll have
    "priv" button as http://server.com/myservlet?skip=0&max=10 and
    "next" button as http://server.com/myservlet?skip=20&max=10 and so on...
    hope this makes sense..
    Shantanu

  • Block database access using toad or other tools

    We have a forms application running on oracle database 10g release 2, with the users created in the application the database can be accessed using the same id's through sql plus or any other tool. We have already restricted sql plus access by product_user_profile. Is there any other way to make sure toad or any other tool can be stopped from accesing the database.
    Thanks
    Eric

    eric_in wrote:
    We have a forms application running on oracle database 10g release 2, with the users created in the application the database can be accessed using the same id's through sql plus or any other tool. We have already restricted sql plus access by product_user_profile. Is there any other way to make sure toad or any other tool can be stopped from accesing the database.
    Thanks
    EricHi Eric
    I've a blog post on this issue. You can look for .exe extentsion of the program which connects to the database
    http://kamranagayev.wordpress.com/2009/10/04/block-developers-from-using-toad-and-other-tools-on-production-databases/

  • Help...create database(access) using java

    i had developed an java application that capture packet using Jpcap but i dont know how to keep the packet captured into database(access).i can save the packet captured in text file but not in database(access).i already had the database conectivity but i don't know how to insert the packet caputred in the table in access, is it using sql statement like INSERT INTO? or else?i realy don't know.can someone help me....?

    i can save the packet captured in to text file but not in database(access).I guess that you wish to get a databse file with your data, not a simple insert sql question.
    1. commercial solution: HXTT Access(http://www.hxtt.com/access.html), which supports create database, create table sql, and batch insert data from any JDBC driver.
    2. free solution: jdbc-odbc bridge and dsn-less jdbc url, you need to prepare a blank mdb file with blank table, then copy that blank mdb file into new mdb file, then repeat insert sql for that new mdb file.

  • Jsp database access using odbc - please help

    Hi friends,
    I�m trying a very simple database access program in jsp data base access using odbc. Odbc has to be used because thin driver or other drivers may not be available in every system of our college and as you know it's not that easy to make changes to those systems. My problem is so simple. I always get an exception in my program.
    My jsp content is as simple as:
    <%@ page import="java.lang.*,java.sql.*,java.io.*,registerbean" %>
    <jsp:useBean id="db" class="registerbean" scope="session"/>
    <%
    String str="insert into reg values('" + db.getName() + "','" + db.getUname() + "','" + db.getPass() + "'," + db.getAge() + ",'" + db.getSex() + "','" + db.getAdd() + "','" + db.getUgcourse() + "','" + db.getUgqual() + "'," + db.getPer() + ",'" + db.getIadd() + "')";
    try
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection con=DriverManager.getConnection("jdbc:odbc:yogaesh","scott","tiger");
    Statement stmt=con.createStatement();
    stmt.executeUpdate(str);
    }catch(Exception e1){out.println(str);};
    %>
    the table reg has the structure:
    Name Null? Type
    CNAME VARCHAR2(20)
    UNAME VARCHAR2(20)
    CPSWD VARCHAR2(20)
    CONFPASS VARCHAR2(20)
    CAGE NUMBER
    CSEX VARCHAR2(5)
    CADD VARCHAR2(100)
    COURSE NUMBER
    CQUAL VARCHAR2(10)
    CPER NUMBER
    IADD VARCHAR2(100)
    The registerbean.java file is as below: (This seems to work fine because I tried printing the values using <%= %> tag and it worked out fine and moreover the query string is intact.)
    import java.io.*;
    import java.util.*;
    import java.lang.*;
    public class registerbean
    private String name,uname,pass,cpass,age,sex,add,ugcourse,ugqual,per,iadd,otherugqual,ccode;
    public void setName(String a)
    name=a;
    public void setUname(String a)
    uname=a;
    public void setPass(String a)
    pass=a;
    public void setCpass(String a)
    cpass=a;
    public void setAge(String a)
    age=a;
    public void setSex(String a)
    sex=a;
    public void setAdd(String a)
    add=a;
    public void setOtherugqual(String a)
    otherugqual=a;
    public void setCcode(String a)
    ccode=a;
    public void setUgcourse(String a)
    ugcourse=a;
    public void setUgqual(String a)
    ugqual=a;
    public void setPer(String a)
    per=a;
    public void setIadd(String a)
    iadd=a;
    public String getName()
    return(name);
    public String getUname()
    return(uname);
    public String getPass()
    return(pass);
    public String getCpass()
    return(cpass);
    public String getAge()
    return(age);
    public String getCcode()
    return(ccode);
    public String getSex()
    return(sex);
    public String getAdd()
    return(add);
    public String getUgcourse()
    return(ugcourse);
    public String getUgqual()
    return(ugqual);
    public String getPer()
    return(per);
    public String getIadd()
    return(iadd);
    public String getOtherugqual()
    return(otherugqual);
    I initially thought the problem was with str but then str seems to be perfect and I get a string of the form �insert into reg values('c','c','c',98,'Male','c','B.Tech, Applied Artificial Neural Networks','HSC',9898,'h')� which I verified through a javascript debugger. The session scope used is to get values through the db bean from another jsp file. The problem is in the executeUpdate() line of this code. I even tried changing the updation table, but in vain. What could be done to rectify this? Please help me out and please do remember that I have no option but to use odbc.
    Thanks in advance.
    R. Yogaesh.

    I didn't verify the type of exception and i'm now going to do that, but then when the string is as perfect as needed, what is the need for a prepared statement? What is the basic difference between the two? And basically what is the problem with this piece of code which creates an exception? Please reply as soon as possible.
    Thankyou very much.
    R. Yogaesh.

  • Database access using windows authentication

    We are updating our Applications to use single sign on and are running into a problem with database access. We are using CF11 Enterprise and SQL Server 2008 on IIS 7.5.
    We have set up the ColdFusion Application Service to run under an AD service account and have created the data sources in CFAdmin leaving the username and password blank. The data sources verify and all seems good. The problem comes when running a query. The credential passed to the database is the service account and not the windows authenticated user. As such the query fails. What are we missing to get CF to pass the Windows Authenticated user credential instead of the service account?
    Thanks
    Tim

    ColdFusion does not pass user's credentials to the database connections by default, and cannot pass Windows Authentication credentials that way.  It only sends the service account's credentials (if you leave username/password blank as you have done).  The only way to pass user credentials is to put them into the individual query calls themselves, and even then you can't pass Windows Authentication credentials.  You would have to use SQL Server Logins, and create accounts for each user.
    I think most people are using either a dedicated SQL Server login for ColdFusion and run all queries under that account, or they do as you have already done and use Windows Authentication along with the ColdFusion service account.  If you need an audit trail, then pass usernames into the insert/update queries and store them manually along with the other data you are inserting/updating.
    -Carl V.

  • Locking database fields using Servlet

    Hi,
    I am developing a servlet application which is used to access and/or modifying a database on a server. I am now asked for locking fields if a user is accessing the information while others have already loaded the same information page preventing it from changing the same fields that an other user is currently viewing.
    The problem is that my server, running the servlet, is the only one to access the DB (using JDBC) and the connection is always done with the same username/pwd. This connection is done for a short period of time, that is, the time to create the HTML page.
    Is there a way to keep the servlet knowing who is connected to it? With that feature, I could ask for username and pwd for each user and then locking tables on the DB for them.
    I'm I clear enough? I don't feel so... ;)
    Thanks in advance for any hints!
    Snoozer

    Did you try to use:
    request.getRemoteUser()

  • Database access using LDAP (AD) credentials

    I am looking for any information about how to allow users access to a database and underlying applications that rely on DB authentication methods, to be able to access without specifying username/password credentials.
    I know that OP$ accounts can be used in which case a user does not need to specify username/password credentials... but last I checked on this I thought there were security concerns related to this and this approach was not generally recommended.
    We want users to be able to access databases and applications without login since they have already authenticated to the network using their credentials as authenticated via AD... So my quesrion is...
    Is there a way that credentials can be passed from AD/OID using network login credentials of users to allow access to the database and applications? Is there a way to have an Oracle database talk directly to an AD LDAP solution or is it required that you implement OID and SSO?
    I hope that makes sense.... Bottom line is we want to not require username/password authentication to every Oracle database application for users. We would like a way to use their AD credentials....
    Is this possible?
    Or can it only be accomplished with an OID/SSO inplemenetation?
    Or is this essentially OPS$ accounts? are there security concerns with ops$ accounts.
    Thanks.

    This can be achieved by means of an enterprise user.
    You may want to read this HowTo Document: How to set up Enterprise User Security.
    ~ Madrid

  • Database access using DAO

    I'm new to Struts and would like to know about accessing database in struts
    using Data Access Object (DAO) pattern.
    It would be better If anybody can point me to any good source on how to write the DAO
    and how to configure the Struts-Config.xml in order to use the DAO pattern,
    Any sample would be better too.
    Any help pretty much appreciated. Thanks in advanced.

    I'm new to Struts and would like to know about
    accessing database in struts
    using Data Access Object (DAO) pattern.
    It would be better If anybody can point me to any
    good source on how to write the DAO
    and how to configure the Struts-Config.xml in order
    to use the DAO pattern,
    Any sample would be better too.
    Any help pretty much appreciated. Thanks in advanced.Hi,
    I am developing a web application with struts and DAO pattern.
    If you study this pattern you will know that it makes connection to database. and there is two way to obtain a connection object from your action class:
    1. througth DriverManageras mention in java tutorial JDBC Basics:
    2. througth Datasource as mention in java 1.3 turorial, chapter 31 "Resource Connections", sections "DataSource Objects and Connection Pools" and "Database Connections". This tutorial show you how to set up Datasource for Sun Java System Application Server Platform througth the j2ee deployment tool.
    in the case of having an different platform from Sun Java System Application Server you must know how to correctly set up the datasource object with your web or ejb container.
    I have chosen the second solution for my webApp. I am using tomcat co-bundle with netbeans 4.0. those ares the configuration files of my web app (according to netbeans 4.0 help context "Setting Up a Tomcat Database Connection Pool"):
    file server.xml
    <Resource name="jdbc/WebForumDB" type="javax.sql.DataSource"/>
    <ResourceParams name="jdbc/WebForumDB">
    <parameter>
    <name>validationQuery</name>
    <value>select * from "PBPUBLIC"."USER_ACCOUNT_TAB"</value>
    </parameter>
    <parameter>
    <name>maxWait</name>
    <value>5000</value>
    </parameter>
    <parameter>
    <name>maxActive</name>
    <value>4</value>
    </parameter>
    <parameter>
    <name>password</name>
    <value>PBPUBLIC</value>
    </parameter>
    <parameter>
    <name>url</name>
    <value>jdbc:pointbase://localhost:9092/WebForumDB</value>
    </parameter>
    <parameter>
    <name>driverClassName</name>
    <value>com.pointbase.jdbc.jdbcUniversalDriver</value>
    </parameter>
    <parameter>
    <name>maxIdle</name>
    <value>2</value>
    </parameter>
    <parameter>
    <name>username</name>
    <value>PBPUBLIC</value>
    </parameter>
    </ResourceParams>
    file context.xml
    <ResourceLink name="jdbc/WebForumDB"
    type="javax.sql.DataSource"
    global="jdbc/WebForumDB"/>
    file web.xml
    <resource-ref>
    <description>Web Forum Database</description>
    <res-ref-name>jdbc/WebForumDB</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
    </resource-ref>
    after all configuration work your DAOFactory class should nearly looks like this (my DAO pattern obtain connection througth Datasource object):
    public class PointbaseDAOFactory
    extends DAOFactory {
    private static DataSource ds = null;
    private static String dbJndiName = "java:comp/env/jdbc/WebForumDB";
    /** Creates a new instance of PointbaseDAOFactory */
    public PointbaseDAOFactory(){}
    public static Connection createConnection()
    throws DAOException {
    InitialContext ic = null;
    Connection conn = null;
    try {
    //lookup datasource
    ic = new InitialContext();
    log.info("method: createConnection, lookup dataSource jndi name: " + dbJndiName);
    ds = (DataSource) ic.lookup(dbJndiName);
    if (ds == null){
    throw new DAOException("method: createConnection, null Datasource from jndi lookup");
    // get connection
    conn = ds.getConnection();
    } catch (SQLException e){
    throw new DAOException("method: createConnection, SQLException",e.getMessage());
    } catch (NamingException e){
    throw new DAOException("method: createConnection, NamingException",e.getMessage());
    return conn;
    hope this help you. :-)

  • SO 8 database access using BASIC

    I created a database using StarOffice 8 and I want access it through BASIC. Unfortunately I keep getting the following error:
    Table not found in statement [SELECT ItemDescription FROM Inventory].
    This should work because my SQL query uses the same syntax and it works.
    Here is the code (copied nearly verbatim from the StarOffice BASIC manual):
    Dim DatabaseContext As Object
    Dim DataSource As Object
    Dim Connection As Object
    Dim InteractionHandler as Object
    Dim Statement As Object
    Dim ResultSet As Object
    DatabaseContext=createUnoService("com.sun.star.sdb.DatabaseContext")
    DataSource=DatabaseContext.getByName("TestDatabase")
    If Not DataSource.IsPasswordRequired Then
      Connection=DataSource.GetConnection("","")
    Else
      InteractionHandler=createUnoService("com.sun.star.sdb.InteractionHandler")
      Connection=DataSource.ConnectWithCompletion(InteractionHandler)
    EndIf
    Statement=Connection.createStatement()
    ResultSet=Statement.executeQuery("SELECT ItemDescription FROM Inventory")
    If Not IsNull(ResultSet) Then
      While ResultSet.next
        MsgBoxResultSet.getString(1)
      Wend
    EndIf

    This can be achieved by means of an enterprise user.
    You may want to read this HowTo Document: How to set up Enterprise User Security.
    ~ Madrid

  • Assigning database access using Shared Services

    I need to be able to assign security to a specfic database within an application. We have an application that has two databases. I provisioned the necessary group to the correct application to give them access. However, I only want that group to be able to see one of the two databases. How do assign security using Shared Services to provision access to just that database and not the other.
    Thank you very much for your help.
    Info:
    Version of Shared Services - version 9.3.1

    So I am going to answer my own post just incase anyone else is wondering the answer. I found the information right out of the hyp_security_guide.pdf - Security Administration guide. It states that - In Shared Services, if an Essbase application contains multiple databases, the databases must have the same user security access levels.
    This is just my two cents, but I would think this might be something you would consider adding to Shared Services in future releases.

  • Database access using Entity Beans

    How does it work? In the examples I've seen, there is no SQL statement
    being generated, and I no code establishing the JDBC bridge...
    What am I missing? How do I look up a record in a database using an
    entity bean?
    Thanks!!!
    -Dan

    The Entity Bean remote interface methods access the database.
    InitialContext ic=new InitialContext();
    EntityBHome eh = (EntityBHome)ic.lookup("com.ejb.EntityBHome");
    EntityB entityB=eh.findByPrimaryKey(primarykey pk);
    [email protected] (Dan M) wrote:
    How does it work? In the examples I've seen, there is no SQL statement
    being generated, and I no code establishing the JDBC bridge...
    What am I missing? How do I look up a record in a database using an
    entity bean?
    Thanks!!!
    -Dan

  • Slow DataBase Access using JDK 1.5 and MySQL

    Hi EveryBody,
    I am using Jdk1.5 in my project and mysql 5.0 as my database server.
    The problem is that, to create a connection for the first time it takes upto 20 to 25 seconds.
    when i use the 1.4.2 with the same mysql version it takes only 2 seconds.
    In both the cases i am using the JDBC driver (com.mysql.jdbc.Driver )
    I cannot understand the problem with the jdk1.5,
    so, please help me in resoving this issue.

    I encountered same problem with connecting Oralce.
    It's a bug of JDK1.5.
    You need upgrade JDK1.5 to latest version,or use IP address instead of machine name(such as locahost etc.).
    Message was edited by:
    LucasLee

  • Problems with database access in Servlet Apllication (Duke's Bookstore)

    Hi! My name is Elena Veretilo! I am so newbie in JavaEE. So I really need you help and advice!!!
    I started to learn JavaEE with "The JavaEE5 tutorial for Sun Java Application Server 9.1" (http://java.sun.com/javaee/5/docs/tutorial/doc/) and this tutorial recommended the next examples: http://java.sun.com/javaee/5/docs/tutorial/information/download.html. I try to work in NetBeans 6.0 and NetBeans 6.5.
    First problem - I couldn't add Sun Java Application Server 9.1 to NetBeans' server list - it just doesn't see the installed Sun Java Application Server 9.1.
    Second problem - I couldn't run Duke's Bookstore example (from tutorial examples) - something wrong with working (maybe creating or accessing) database. The Database Server started, GlassFish Server also started, so I don't know where the problem could be.
    There is exception:
    Exception [TOPLINK-4002] (Oracle TopLink Essentials - 2006.8 (Build 060830)): oracle.toplink.essentials.exceptions.DatabaseException
    Internal Exception: org.apache.derby.client.am.SqlException: Table/View 'WEB_BOOKSTORE_BOOKS' does not exist.Error Code: -1
    Call:SELECT BOOKID, FIRSTNAME, SURNAME, ONSALE, INVENTORY, CALENDAR_YEAR, TITLE, PRICE, DESCRIPTION FROM WEB_BOOKSTORE_BOOKS WHERE (BOOKID = ?)
    bind => [203]
    Query:ReadObjectQuery(com.sun.bookstore.database.Book)
    If anybody had learned this tutorial and examples or just know what I need to do, please help me!!!!! If it's possible, tell me step by step, what I need to do!
    And one more question - do I really need Sun Java Application Server 9.1 to work with or GlassFish includes Sun Java Application Server 9.1?????

    [http://forums.sun.com/thread.jspa?threadID=5350426]
    Crossposting without notification is very rude. Please stick to one topic.

  • Database access using HTML, JSP, JavaBean, & Access

    I am trying to create an HTML page that a user logs into and can choose to query, add, delete or modify a specified database. I have created the HTML, the JSP, and access database but I can't figure out how to have 4 different JSP pages(one for each option) to get information from one JavaBean. PLEASE HELP

    http://swforum.sun.com/jive/thread.jspa?threadID=53106&tstart=0

Maybe you are looking for

  • How do I create a spinner for an "Activity" Task field???

    I am in need of a "spinner" for one of my Activity Task fields. What I term a spinner is basically a numeric field which which can be increased or decreased by the user through the use of either an up or down arrow next to the numeric field. Example:

  • How to Remove Export to Excel

    Hi All,       How to Remove Export to Excel and Export to CSV in BW Report.....if any one know please tell me the proper steps....really i appreciate that person work.... this is very urgent..... Regards, Jagadish Babu Kanikanti.

  • Import broken in SQL Developer version 1.5.1

    I try and import a .csv file and one of the Target Table Columns has no Data Type, which is odd because it does or else it wouldn't exist to begin with. I liked the older version. Less buggy and so much easier to use when trying to import...and it wo

  • IMovie consistently crashes when editing or when playing back in storyboard

    Have uploaded a 12 hour video from a Canon GL2 to iMovie 08 directly to a Lacie external drive. There were no issues uploading. There were no issues selecting clips and moving them into the storyboard. The problems started when the editing process st

  • Folio changes don't show up in the app

    Hi. We have two folios in two different apps on which our changes don't reach the app. If we update the folio, there is no "Update" button. If we unpublish it, it stays in the app. If we republish it with new content under a new product ID, the old f