How to connect database

This is my jsp file!(
Claims Processing: Data Entry
Created on Apr 18, 2007
To change the template for this generated file go to
Window>Preferences>Java>Code Generation>Code and Comments
package Database;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.sql.DataSource;
@author Administrator
To change the template for this generated type comment go to
Window>Preferences>Java>Code Generation>Code and Comments
public class DataRetriever {
     Connection connection = null;
     public DataRetriever(String jndiName) {
          try {
               Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
               connection =
                    DriverManager.getConnection(
                         "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=HRMS;User=sa;Password=sa");
               System.err.println("Database connection established AGAIN");
          } catch (Exception e) {
               System.err.println("Cannot connect to database server - " + e);
     private void getConnection(String jndi) {
          try {
               Context ctx = new InitialContext();
               if (ctx == null) {
                    throw new Exception("Boom - No Context");
               DataSource ds = (DataSource) ctx.lookup("java:comp/env/" +jndi);
               System.err.println(jndi);
               if (ds != null) {
                    connection = ds.getConnection();
          } catch (Exception e) {
               e.printStackTrace();
               connection = null;
     public ResultSet execSelectQuery(String sql) {
          try {
               if (connection == null) {
                    return null;
               Statement s = connection.createStatement();
               return s.executeQuery(sql);
          } catch (SQLException e) {
               e.printStackTrace();
               return null;
     public int execUpdateQuery(String sql) {
          try {
               if (connection == null) {
                    return -1;
               Statement s = connection.createStatement();
               return s.executeUpdate(sql);
          } catch (SQLException e) {
               e.printStackTrace();
               return -1;
     public void terminate() {
          try {
               connection.close();
          } catch (SQLException e) {
               e.printStackTrace();
This is the servlet.
package servlet;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import bean.createClaimsBean;
public class CreateClaimsServlet extends HttpServlet {
protected void doGet(
HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
protected void doPost(
HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
private void processRequest(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException{
String mySqlJndiName =
this.getServletContext().getInitParameter("MySql JNDI");
createClaimsBean cb = new createClaimsBean();
String bd = request.getParameter("textfield1");
String pl = request.getParameter("textfield2");
String pa = request.getParameter("textfield3");
String bn = request.getParameter("textfield3");
String d = request.getParameter("D1");
String ta = request.getParameter("textfield4");
System.out.println("n");
cb=cb.registerCreateClaims(bd, pl, pa, bn, d, ta, mySqlJndiName);
request.getSession().setAttribute("registerCreateClaims", cb);
request.getRequestDispatcher("/WEB-INF/pages/regsuccess.jsp").forward(request,
response);
Lastly it is the java file.
Created on Apr 19, 2007
To change the template for this generated file go to
Window>Preferences>Java>Code Generation>Code and Comments
package bean;
import Database.DataRetriever;
@author Administrator
To change the template for this generated type comment go to
Window>Preferences>Java>Code Generation>Code and Comments
public class createClaimsBean {
     private String billDate;
     private String plans;
     private String panel;
     private String billNo;
     private String dependent;
     private String totalAmt;
     public createClaimsBean(String billDate,String plans,String panel,String billNo,String dependent,String totalAmt)
          this.billDate = billDate;
          this.plans = plans;
          this.panel = panel;
          this.billNo = billNo;
          this.dependent = dependent;
          this.totalAmt = totalAmt;
@return
     public String getBillDate() {
          return billDate;
@return
     public String getBillNo() {
          return billNo;
@return
     public String getDependent() {
          return dependent;
@return
     public String getPanel() {
          return panel;
@return
     public String getPlans() {
          return plans;
@return
     public String getTotalAmt() {
          return totalAmt;
@param string
     public void setBillDate(String string) {
          billDate = string;
@param string
     public void setBillNo(String string) {
          billNo = string;
@param string
     public void setDependent(String string) {
          dependent = string;
@param string
     public void setPanel(String string) {
          panel = string;
@param string
     public void setPlans(String string) {
          plans = string;
@param string
     public void setTotalAmt(String string) {
          totalAmt = string;
     public createClaimsBean{
     public void registerCreateClaims(String mysql, String billNo, String dependent, String panel, String plans, String totalAmt)
     DataRetriever data = new  DataRetriever(mysql);
    String sql= "INSERT INTO claims VALUES (billDate, billNo, dependent, panel, plans, totalAmt)";
    data.execUpdateQuery(sql);
    data.terminate();
How to connect sql so that i m able to insert new data into the database?
Message was edited by:
        fatimah rasheed

Hi Fatimah,
You are on the right way. You need a DataSource to get Connection to the DB and execute queries through it. Have a look at <a href="http://help.sap.com/saphelp_nw04/helpdata/en/15/6d56f65fb59e4db97253c89c5cfefd/frameset.htm">this</a> page for more information on setting up a reference to the DataSource from your Web application.
The procedure for creating a custom DataSource is described <a href="http://help.sap.com/saphelp_nw04/helpdata/en/bb/69da54d8aedc419d46d9ea074e4d41/frameset.htm">here</a>. You can also <a href="http://help.sap.com/saphelp_nw04/helpdata/en/7f/d84b25d49846819d08e1c8ba03a9cd/frameset.htm">use the default DataSource</a>.
Hope it helps!
-Vladimir
PS. Don't use java.sql.DriverManager directly in a J2EE environment. It is designed for standalone usage in the J2SE environment. The recommended way for J2EE is to go through a <b>javax.sql.DataSource</b> object.

Similar Messages

  • How to connect database to mobile device

    hi,
    i want to know how can connect my mobile phone to my oracle database. i want to send a sms (student roll number)& want to get the marks of that student.
    what i need prerequisites to do this & what should be the steps to install this .
    thxs

    Super,
    I'm not sure which database version you're trying to achieve this for hence, I'd recommend you to go through the following 10g documentation for further understanding:
    Oracle&reg; Database Lite Administration and Deployment Guide 10g
    http://download.oracle.com/docs/cd/E12095_01/doc.10302/e12089/admdb.htm#BDCBEGFI
    Hope this helps.
    Regards,
    Naveed.

  • How to connect database(MSAccess ) in j2me

    hi,
    i'm new to j2me. can anyone tell me how to connect MsAccess database with the j2me.and also whether it is possible to connect or else we have to use some other database such as Mysql or oracle.
    thanx a lot in advance
    regards
    laxmi

    Not directly. Please use the search, was already asked numerous times!

  • How to connect DataBase 9i  with 10g Developer Suit

    Hi Every body , how i connect
    Oracle9i Enterprise Edition Release 9.0.1.1.1 DataBase with 10g Developer Suit ????
    when i'm trying to run my program i just can run it for the first time :( . when i'm
    trying to run it for the second time i receive this msg
    <html> <head> ORACLE FORMS.</head>
    <body onload="document.pform.submit();" >
    <form name="pform" action="http://ABUKARAKI.AHU.EDU.LOCAL:8889/forms90/f90servlet" method="POST">
    <input type="hidden" name="form" value="C:\Documents and Settings\Admin\Desktop\MODULE1.fmx">
    <input type="hidden" name="userid" value="tt/tt@oracle">
    <input type="hidden" name="obr" value="yes">
    <input type="hidden" name="array" value="YES">
    </form> </body></html>

    Create your forms working directory.
    add that path to default.env
    and also edit parameter in formsweb.cfg to point to you main form.
    This way by default when you go to http://ABUKARAKI.AHU.EDU.LOCAL:8889/forms90/f90servlet it will open your main form.
    From main form you can open your other forms.

  • How to connect database(oracle 10g) and retreive values using poral 10

    can anyone help me how to connect to database and retreive values in detail and also please post the sample code if u have any.

    Hello
    Thanks for your reply
    I tried to connect and here is the result: see below
    [oracle@ebstailin 11.1.0]$ sqlplus / as sysdba
    SQL*Plus: Release 11.1.0.7.0 - Production on Sat Jul 17 15:35:31 2010
    Copyright (c) 1982, 2008, Oracle. All rights reserved.
    Connected to:
    Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
    SQL> CONNECT apps/apps
    Connected.
    SQL>
    But still cannot connect using ORACLE SQL Developer
    thanks

  • How to Connect Database Using Script?

    Hi all,
                    Am using Adobe InDesign CS3. Is there any way to connect database from Adobe InDesign CS3 Scripting (Javascript)? Thanks in advance.
    Regards,
    Mohan

    I don't know javascript so I can't help with that part.
    The system plug in you need is from Actual Technologies : http://www.actualtechnologies.com/ The setup for that is detailed in their instructions. You will probably want to set it up for system-wide access, not by user. I found system-wide access more reliable, fwiw.
    For Applescript I send a command through the Terminal/command line that returns the data from the query.
    Here is Applescript:
    set query to "YOUR DB QUERY"
    set results to (do shell script "echo \"" & query & "\" | iodbctest \"dsn=" & dsn & ";uid=" & uid & ";pwd=" & pwd & "\" | awk '{ if (match($0,\"SQL>\")) {k++; if (k==1) next; if (k==2) exit; } if (k==1) print; }'")
    You can probably do something similar in Javascript. You'll have to parse out the text data returned then. I think there may be plug-ins for InDesign that can directly connect to a database (?). Or some plug-ins like inData can take their data passed from a script as well.
    Chris

  • How to connect database using coding in trigger in forms

    Oracle forms6i
    Hai All
    Is there any possiblity to connect database using coding.
    For example when we open a form and we use some button and write some coding and when we execute a small will appear and we give username,connection identifier and database name.
    Is it any possible there when we create a button and in that button we write coding our database name,connectionid and user and when we exe it will internally connect database Pls tell me..
    Regards
    Srikkanth.M

    use LOGON Procedure
    PROCEDURE LOGON
      (username  VARCHAR2,
       password  VARCHAR2);
    logon('scott','tiger@orcl');Mr.Srikkanth.M if u dont close ur old questions dont expect others to answer ur question everytime......so plz remember if u think the person's answer is helpful or correct mark it accordingly
    Thanks :)
    Baig
    [My Oracle Blog|http://baigsorcl.blogspot.com/]

  • How to connect database using JSF??

    When I deployed a JSF war file which was connected to MySql on Sun Application Server, then lanuched it, why there was an error message like "HTTP Status 503 - This application is not currently available". Can anyone tell me why? thanks.

    Thanks pringi~~!!
    I still have problems about the database connection. I had tried many examples which were provided by some books. However, once I deployed the application, it still got problems. Can anyone help me and provide a example about the database connection. Thanks a lot.

  • How to connect database using JDBc?

    Hi All,
    I developed one Microsoft Access Database named "Test.mdb" in my "C" drive,
    i used
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    String url = "jdbc:odbc:C:\Test";
    Connection con=DriverManager.getConnection(url);
    While executing the above code, I m getting the following error
    Error occurs java.sql.SQLException : No suitable driver
    please help me what is the problem..i did code in proper try catch block ... so dont worry but let me know what is exactly reson behibd getting this querry....
    my email id is : [email protected]
    waiting for ur reply.. its urgent

    While executing the above code, I m getting the following error
    Error occurs java.sql.SQLException : No suitable driverDon't post your e-mail.
    This error always means that the URL you gave to connect to the database is incorrect. Yours is indeed wrong:
    String url = "jdbc:odbc:C:\Test";You can correct it in either one of two ways:
    (1) Create a DNS in Windows that points to your database (call it "Test") and change the URL so it says
    String url = "jdbc:odbc:Test";(2) You can skip creating a DNS and use a connection String that looks like this:
    "jdbc:odbc:DRIVER={Microsoft Access Driver (*.mdb)};DBQ=<database-path>";In your case, <database-path> is "C:\\Test"
    Better read a tutorial:
    http://java.sun.com/docs/books/tutorial/jdbc/
    %

  • How to connect database using oracle SQL developer

    Hello
    I am newbie in EBS R12
    I downloaded Oracle SQL Developer
    and create new database conenction
    Connection name: ebs demo db connection
    username:
    password:
    Role: Default
    Connection type: Basic
    Hostname: ebstailin.demo.com
    Port: 1521
    SID: clone
    when i try this there is an error
    Status: Failure-Test failed: lo exception: The Network Adapter could not establish the connection
    no idea about this
    but i used the apps/apps as username and password
    please help
    thanks
    Edited by: cheesewizz on Jul 16, 2010 11:35 PM

    Hello
    Thanks for your reply
    I tried to connect and here is the result: see below
    [oracle@ebstailin 11.1.0]$ sqlplus / as sysdba
    SQL*Plus: Release 11.1.0.7.0 - Production on Sat Jul 17 15:35:31 2010
    Copyright (c) 1982, 2008, Oracle. All rights reserved.
    Connected to:
    Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
    SQL> CONNECT apps/apps
    Connected.
    SQL>
    But still cannot connect using ORACLE SQL Developer
    thanks

  • How to connect database using type4 driver(dsn or dsnless connection)

    please send any one reply answer

    One reply - not possible.
    DSN/DSNless refers to a specific driver. And that driver is not a type 4 driver. So it is not possible.

  • Help how to connecting Oracle SQL Developer 3.0  with Oracle Database 11g

    Hello,
    I'm new in oracle developer yesterday i setup in my laptop database 11g the last version (11.2.0.1.0), well i follow steps still i got succeed to install, and i got my local host URL and i test my user name and password work very well, my problem now is i try to connect database 11g using Oracle SQL Developer 3.0 (3.0.04.34) but always filed and with my little experience i don't know where the wrong. as i said i test database after finish install is work fine the my URL is https://Ahmed-HP:1158/em and i test my username and password that i already set before is enter normal in my local database, please i need help to know how i connect database with Oracle SQL Developer 3.0 (3.0.04.34).
    Thanks,

    885173 wrote:
    EdStevens, thanks for your quick answer, sorry for my explain was doesn't clear, i open oracle sql developer and choose new connection i set connection name system_orcl username:system password:*i set my password that i create when i setup database*
    -Now the link that i got after finish install database is https://Ahmed-HP:1158/em so i have question about this point Hostname and port if the link to access database is this https://Ahmed-HP:1158/em so this mean i typing at Hostname:localhost and port:1158 ?
    because the message when i test connection always is filed and I'm sure i typing username and password and SID:orcl as i set when install database.port 1158 is what the dbcontrol (Oracle Enterprise Manager) is listening on. OEM is NOT the database. As far as the database is concerned, OEM is "just another client".
    Actually, the database doesn't listen for requests on any port. There is another process, the "listener" that listens for requests to connect to the database. Typically, it listens on port 1521. You should have a tnsnames.ora file set up to resolve a connection request to the correct host. You can read more on this at http://edstevensdba.wordpress.com/2011/02/09/sqlnet_overview/

  • How to connect my access database using applet?

    hi all,
    i need to connect my access database in my applet program which should work like an atm machine..I dont know how to connect it. Im new to applet same thing in JDBC application. Please help i terribly need it, our deadline in our case study is fast approaching and i still dont know how to do it. I tried the tutorial but i received some sql exception error. thanks!

    Try this link
    http://java.sun.com/docs/books/tutorial/jdbc/basics/

  • How to connect a PDF form to SQL server database through web service?

    Hi,
    I'm new to LiveCycle designer. I have designed a PDF form in LC designer ES2, which suppose to take a personnel number and retrieve the personnel information from a SQL server database. Currently its working fine with XML data and a search button, but I need to securly connect to a database through web service. I know how to connect to a wsdl file through designer. What I need is a wsdl file to connect the form to database. For this purpose, is there any WSDL code to use as the web service?
    I really appreciate your help and advice.

    Hi,
    I'm new to LiveCycle designer. I have designed a PDF form in LC designer ES2, which suppose to take a personnel number and retrieve the personnel information from a SQL server database. Currently its working fine with XML data and a search button, but I need to securly connect to a database through web service. I know how to connect to a wsdl file through designer. What I need is a wsdl file to connect the form to database. For this purpose, is there any WSDL code to use as the web service?
    I really appreciate your help and advice.

  • Members only area of website and how to connect it to existing database

    I am trying to create a members login section on an existing website. We have a MS Access database of clients, and I need the website login creation to be able to look at our database and only let the person create an account, if they are on that list. 
    I've successfully completed a walkthrough/tutorial on creating a members only area of a website, but that allows anyone and everyone to create an account. I need a way to force that check before the new user account is allowed. Any help will ge greatly appreciated!

    Hi,
    According to your description, I think your issue is more about how to connect to Access database from your web site, instead of Access development.
    Which type of connection do you want to use? Is it ADO.NET?
    If so, I suggest you posting in ADO.NET Managed Providers
    forum for more effective responses.
    If not, you can choose a proper forum based on the type of the connection or your developing language.
    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.

Maybe you are looking for

  • How can I find out the incoming call and out going call from my orher chine

    How will I know if my friend knows who I call

  • Do you have to own a copy of Photoshop before enrolling in the creative cloud?

    I own Lightroom but currently do not own Photoshop. Do i have to own Photoshop for the Creative Cloud, or for $9.99 mo am I essentially renting both of them? Judy Lepire

  • Invoking a Remote Method

    The Question is ? Suppose there is a object running on system, Say A. Another Object/Client want to invoke a method of the object in the System A and that method returns some value. Now the problem is if the method invoked returns the values in more

  • HP Notebook 2000 cooling fan issue

    Hey, everyone. I've had my HP Notebook 2000 for a few years and I've discovered my first major issue just a few days ago when the cooling fan stopped working. I don't really mind it too much because I have a USB-powered cooling fan that my laptop res

  • 2.8Ghz Prescott CPU

    I recently received this MoBo from MSI as a warranty replacement for an SIS655 Max MoBo. The board came by itself with no cables or drivers (no box for that matter). I have no way of knowing what BIOS version is currently installed. I purchased a 2.8