Connecting to database help

First let me say sorry as i have already started this post in another thread, but know one seems to be replying to it any more. the other thread can be found out: http://forum.java.sun.com/thread.jspa?messageID=9413573
package coreservlets;
public class Catalog {
private static CatalogItem[] items =
    {new CatalogItem
        ("hall002",
         "<I>Core Web Programming, 2nd Edition</I> " +
           "by Marty Hall and Larry Brown",
         "One stop shopping for the Web programmer. " +
           "Topics include \n" +
           "<UL><LI>Thorough coverage of Java 2; " +
           "including Threads, Networking, Swing, \n" +
           "Java 2D, RMI, JDBC, and Collections\n" +
           "<LI>A fast introduction to HTML 4.01, " +
           "including frames, style sheets, and layers.\n" +
           "<LI>A fast introduction to HTTP 1.1, " +
           "servlets, and JavaServer Pages.\n" +
           "<LI>A quick overview of JavaScript 1.2\n" +
           "</UL>",
         49.99),
      new CatalogItem
        ("lewis001",
         "<I>The Chronicles of Narnia</I> by C.S. Lewis",
           "The classic children's adventure pitting " +
           "Aslan the Great Lion and his followers\n" +
           "against the White Witch and the forces " +
           "of evil. Dragons, magicians, quests, \n" +
           "and talking animals wound around a deep " +
           "spiritual allegory. Series includes\n" +
           "<I>The Magician's Nephew</I>,\n" +
           "<I>The Lion, the Witch and the Wardrobe</I>,\n" +
           "<I>The Horse and His Boy</I>,\n" +
           "<I>Prince Caspian</I>,\n" +
           "<I>The Voyage of the Dawn Treader</I>,\n" +
           "<I>The Silver Chair</I>, and \n" +
           "<I>The Last Battle</I>.",
         19.95),
      new CatalogItem
        ("alexander001",
         "<I>The Prydain Series</I> by Lloyd Alexander",
           "Humble pig-keeper Taran joins mighty " +
           "Lord Gwydion in his battle against\n" +
           "Arawn the Lord of Annuvin. Joined by " +
           "his loyal friends the beautiful princess\n" +
           "Eilonwy, wannabe bard Fflewddur Fflam," +
           "and furry half-man Gurgi, Taran discovers " +
           "courage, nobility, and other values along\n" +
           "the way. Series includes\n" +
           "<I>The Book of Three</I>,\n" +
           "<I>The Black Cauldron</I>,\n" +
           "<I>The Castle of Llyr</I>,\n" +
           "<I>Taran Wanderer</I>, and\n" +
           "<I>The High King</I>.",
         19.95),
      new CatalogItem
        ("rowling001",
         "<I>The Harry Potter Series</I> by J.K. Rowling",
         "The first five of the popular stories " +
           "about wizard-in-training Harry Potter\n" +
           "topped both the adult and children's " +
           "best-seller lists. Series includes\n" +
           "<I>Harry Potter and the Sorcerer's Stone</I>,\n" +
           "<I>Harry Potter and the Chamber of Secrets</I>,\n" +
           "<I>Harry Potter and the " +
           "Prisoner of Azkaban</I>,\n" +
           "<I>Harry Potter and the Goblet of Fire</I>, and\n" +
           "<I>Harry Potter and the "+
           "Order of the Phoenix</I>.\n",
         59.95)
  public static CatalogItem getItem(String itemID) {
    CatalogItem item;
    if (itemID == null) {
      return(null);
    for(int i=0; i<items.length; i++) {
      item = items;
if (itemID.equals(item.getItemID())) {
return(item);
return(null);
Using the above servlet and this one:
package coreservlets
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
public class browser extends HttpServlet {
  public void doGet(HttpServletRequest request,
                    HttpServletResponse response)
      throws ServletException, IOException {
    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
     Connection conn = null;
     try{
         Class.forName("com.mysql.jdbc.Driver").newInstance();
     } catch(Exception e) {
         System.out.println(e);
     // connecting to database
     try{
         conn = DriverManager.getConnection
        ("jdbc:mysql://MY WEB ADDRESS FOR THE SQL TABLES GOES HERE");
          // System.out.println("Connection to database successful.");
       catch(SQLException se) {
         System.out.println(se);
     try{
          // Get the category from the input form
          String categoryString = request.getParameter("category");
          // check if no category
          if (categoryString == "") categoryString = "Action & Adventure";
         String selectSQL = "select title, director, rating, year_released, price, stock_count, image_name "+
                            "from video_recordings "+
                            "where category = '" + categoryString + "'";
         Statement stmt = conn.createStatement();
         ResultSet rs1 = stmt.executeQuery(selectSQL);
      // output html headers
      String title = "Films in the " + categoryString + " genre" ;
       out.println(ServletUtilities.headWithTitle(title) +
                "><BODY BGCOLOR=\"#a00e0e\">\n" +
              "<center><img src=\"http://localhost:8080/examples/pic.jpg\" width=350 height=200/></center>\n" +
                "<H1 ALIGN=\"CENTER\">" + title + "</H1>\n");
       out.println("<TABLE BORDER=1 ALIGN=\"CENTER\">\n" +
                "<TR BGCOLOR=\"#FFAD00\">\n" +
                "  <TH>Title\n" +
                "  <TH>Director\n" +
              "  <TH>Rating\n" +
              "  <TH>Year Released\n" +
              "  <TH>Price\n" +
              "  <TH>Number in stock\n" +
                "  <TH>image name"
// Retrieve the results
         while(rs1.next()){
              out.println("<TR>" +
                          "<TD>" + rs1.getString("title") + "</TD>" +
                          "<TD>" + rs1.getString("director") + "</TD>" +
                        "<TD>" + rs1.getString("rating") + "</TD>" +
                        "<TD>" + rs1.getDouble("year_released") + "</TD>" +
                        "<TD>" + rs1.getString("price") + "</TD>" +
                           "<TD>" + rs1.getString("stock_count") + "</TD>" +
                          "<TD>" + rs1.getString("image_name")  +"</TD>\n");
                         "<TD> <IMG SRC=\"../images/music/" + image_name +"\">"
    // close the html
    out.println("</TABLE></BODY></HTML>");
// Close the stament and database connection
         stmt.close();
         conn.close();
     } catch(SQLException se) {
         System.out.println(se);
  }How do i merge these two together so that a catalogItem is created by connecting to the database and uses the select statement?? If any one can help me here i would be really grateful as i am having real trouble with this.

Below is what i have come up with (I cut out the code that just gets in the way for this post, eg the connect to database and import statements) My problem is this would only work once has i need to add the item to the array addedItem in the first for loop, can anybody help me with this has i have tried a number of ways but can't get it to compile.
private static CatalogItem[] addedItem
private static CatalogItem[] ItemsInCat;
CatalogItem item;
CatalogItem details;
        int recordingidDB;
     String directorDB;
     String titleDB;
     String categoryDB;
     String imageDB;
     int durationDB;
     String ratingDB;
     String yearDB;
     float priceDB;
     int StockDB;
// Create select statement and execute it
     try{
         String selectSQL = "select title, director, rating, year_released, price, stock_count, image_name "+
                            "from video_recordings " + "'";
         Statement stmt = conn.createStatement();
         ResultSet rs1 = stmt.executeQuery(selectSQL);
         while(rs1.next()){
          recordingidDB = rs1.getInt("recording_id");
          directorDB = rs1.getString("director");
          titleDB = rs1.getString("title");
          categoryDB = rs1.getString("category");
          imageDB = rs1.getString("image_name");
          durationDB = rs1.getInt("duration");
          ratingDB = rs1.getString("rating");
          yearDB = rs1.getString("year_released");
          priceDB = rs1.getFloat("price");
          stockDB = rs1.getInt("stock_count");
           item =
           new CatalogItem
              (recordingidDB, directorDB,titleDB, categoryDB, imageDB, durationDB, ratingDB, yearDB, priceDB, stockDB);
     String title = "Catalog Items";
out.println(ServletUtilities.headWithTitle(title) +
                "<BODY BGCOLOR=\"#a00e0e\">\n" +
              "<center><img src=\"http://localhost:8080/examples/img.jpg\" width=350 height=200/></center>\n" +
                "<H1 ALIGN=\"CENTER\">" + title + "</H1>\n");
     // loop to go over each item in the array of catalogItem
         for  (int i=0; i < ItemsInCat.length; i++) {
           out.println("__________________________");
           details = item;
     if (details == null) {
out.println("SORRY THERE HAS BEEN AN ERROR ");
     } else {       
addedItem[] // needd to store item in array here
     out.println(titleDB + "\n" + priceDB + "\n");
     out.println("</BODY></HTML>");
     public static CatalogItem getItem(int recordingidDB) {
     CatalogItem item;
for(int i=0; i<itemsInCat.length; i++) {
item = itemsInCat[i];
if (recordingidDB.equals(item.getItemID())) {
return(item);
return(null);
// Close the stament and database connection

Similar Messages

  • Help: FORMS SERVER cannot connect to database (forms patch9)

    Hi:
    I've installed oracle 9i database and oracle 9ias 1.0.2.2.2a.
    I configured FormsServlet and it's working very well as i suceed my test in http://machina.domain/servlet/oracle.forms.servlet.ListenerServlet!
    The problem is that i cannot connect to the database and i got the error ORA-12203 TNS: Unable to connect to destination!
    I've changed jserv.properties as recommended in 9ias 10222 release notes by commenting the wrapper.env=ORACLE_HOME in OJSP because it conflicts with forms server home.
    I've read all about this, and i still cannot connect to the database.
    I'm using a forms servlet configuration with IE JVM.
    If anyone can help me... i apreciate it!
    By the way in my jserv.properties forms server config i have:
    # Oracle Forms and Reports Servers
    wrapper.classpath=C:\ORACLE\806\forms60\java\f60srv.jar
    wrapper.classpath=C:\ORACLE\806\forms60\java
    If i have this the Test native method call (JNI) fails, but forms server keeps running. The error is:
    Calling RunformProcess.nInitLib()...
    RunformProcess.nInitLib() failed:
    java.lang.NoClassDefFoundError: oracle/forms/servlet/RunformProcess
    Your server configuration needs correcting. Please refer to the Forms documentation for details
    If i comment the f60srv.jar as showed here i suceed the test
    # Oracle Forms and Reports Servers
    # wrapper.classpath=C:\ORACLE\806\forms60\java\f60srv.jar
    wrapper.classpath=C:\ORACLE\806\forms60\java
    So... anyone help ?
    Ricardo
    PS: I can't understand why oracle keep sending huge amounts of releases of products and everytime they send a new release, that new release keeps coming with new bugs.

    Hi:
    This just connection problem just happen if i use formsservlet http connect mode. if i use normal HTTP (without servlet)connect mode with Jinitiator (1.1.8.16) i successfully connect to database (oracle 9i).
    Anyone there using 9ias 1.0.2.2.2a with forms server servlet and oracle database 9i ?
    thankx

  • I Want to connect to database . plz help

    dear programmers
    i use forms9i and oracle database 9i under winxp. the database is on the local machine .
    to connect database from the form i do the following:
    1-choose file | connect from the main menue
    2-type scott/tiger then click on connect
    the following message appear
    ORA-12560 TNS :protocol adapter error.
    please i urgently need to connect to database
    please help

    dear Pamela Gamer
    I really thank u for helping me .
    I did the following :
    1- from Start menu,I select Programs > Oracle9i Developer Suite > Forms Developer > Start OC4J Instance. I waited till the window displays a message that OC4J has been initialized, and I minimized the window,and i did not close it.
    2-I opened my form and connected my database successfuly.
    3- when i started to run my form the same message appeared ( frm-10142: the http listener is not running on 127.0.0.1 at port 8888 . please start the listener or check your runtime perference)
    i do not know why it appeared again .i want to know what is the problem . in fact i hardly need to shift to forms9i, but this problem makes me disapointed.
    if you know the solution , please help me
    thank u again for helping me
    tarek

  • Connect Oracle Database with help of sql server storedprocedure

    Hii,
              Is there Any way to connect Oracle Database Using sql server storedprocedure.I want access oracle database and take some data and insert into my sql server database.so is there any way to connect in one
    stored procedure to connect oracle database and take some data and insert in to my sql server database.
    Nikunj Nandaniya

    Hello,
    I am getting below error when i kust Clic k on Test Connection in SSMS:
    TITLE: Microsoft SQL Server Management Studio
    The test connection to the linked server failed.
    ADDITIONAL INFORMATION:
    An exception occurred while executing a Transact-SQL statement or batch. (Microsoft.SqlServer.ConnectionInfo)
    Cannot initialize the data source object of OLE DB provider "OraOLEDB.Oracle" for linked server "test".
    OLE DB provider "OraOLEDB.Oracle" for linked server "test" returned message "ORA-12154: TNS:could not resolve the connect identifier specified". (Microsoft SQL Server, Error: 7303)
    For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=10.50.4000&EvtSrc=MSSQLServer&EvtID=7303&LinkId=20476
    BUTTONS:
    OK
    Can you please guide is there any other setting i need to do after install Oracle Client ?
    Best Regards,
    Tushar Malvi

  • Connecting to database -- New Bie Pl help

    Hi all,
    I have posted this question y'day & somebody asked me to post in this forum. So I thought I would. My question is :
    How to I connect to database. I know some thing to get connected to database. If I am not wrong,
    I will be needing a driver, datasource. If i am missing anything then please let me now.
    I will be using jdbcodbc bridge driver which we get by default when we download jdk. But how do i create datasource. I want to use Tomcat as my server.
    Please help me in this regard. I have heard of mySQL as free database. Is it true & how do I use it.

    Here's more help:
    http://developer.java.sun.com/developer/Books/javaprogramming/begjava2/ch19.pdf
    What does Tomcat have to do with this? Is this for a J2EE app? If you're just using straight Java (no J2EE, JSP, etc), then you don't need Tomcat.
    jdbcodbc is for talking to Microsoft Access databases from Java - if you are using MySQL, Oracle, Sybase, or most of the others, you will need a database specific driver module.

  • Help Please!! Not able to connect to database from servlets

    Hi all,
    I hava placed a servlet which connects to a database in examples\web-inf\classes dir. I have specified everything in web.xml. But when I run the servlet it says no suitable driver found even though I have placed the driver tomcat/common\lib\classes12.zip in my classpath . I have also trtied converting the file to jar and running the servlet but I am not able to get the connection to database.
    I get the following error.
    Starting service Tomcat-Standalone
    Apache Tomcat/4.0.6
    Starting service Tomcat-Apache
    Apache Tomcat/4.0.6
    Error in init:oracle.jdbc.driver.OracleDriver
    java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1406)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1254)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:313)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:120)
    at testConnectionServlet.init(testConnectionServlet.java:19)
    at javax.servlet.GenericServlet.init(GenericServlet.java:256)
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:918)
    at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:655)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
    at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
    at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:190)
    at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:475)
    at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
    at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
    at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2347)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
    at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
    at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
    at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:170)
    at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:468)
    at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
    at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
    at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
    at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
    at org.apache.catalina.connector.http.HttpProcessor.process(HttpProcessor.java:1027)
    at org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java:1125)
    at java.lang.Thread.run(Thread.java:484)
    Error in init:No suitable driver
    java.sql.SQLException: No suitable driver
    at java.sql.DriverManager.getConnection(DriverManager.java:537)
    at java.sql.DriverManager.getConnection(DriverManager.java:177)
    at testConnectionServlet.init(testConnectionServlet.java:27)
    at javax.servlet.GenericServlet.init(GenericServlet.java:256)
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:918)
    at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:655)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
    at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
    at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:190)
    at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:475)
    at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
    at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
    at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2347)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
    at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
    at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
    at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:170)
    at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:468)
    at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
    at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
    at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
    at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
    at org.apache.catalina.connector.http.HttpProcessor.process(HttpProcessor.java:1027)
    at org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java:1125)
    at java.lang.Thread.run(Thread.java:484)

    after inserting the line in the classpath for classes12.zip try the whole proc again. if it does not work then u should try putting it in the jdk lib dir and if ok can put it also in the \jdk1.3\jre\lib and \jdk1.3\jre\lib\ext dirs....
    it has worked perfectly for me and i dont c any reason that it should not do for u also.

  • Database Connection problem please help

    Hi,
    I have a servlet that basically connects to the database if the userid and password is correct.
    I have a "login.html" page where the user enters the "userid" and "password".The servlet does the checking and grants access to the user.
    My question is as follows.As soon as I startup tomcat type in the url login.html,then press the submit button,(both the fields are blank) the servlet says "ok" this is this information is present in the database.It should say "not ok".Hope I question is clear.The code for the servlet is given below.
    package package1.structure;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.*;
    import java.util.*;
    import java.sql.*;
    public class AuthenticateServlet2 extends HttpServlet {
    private String user="";
    private String pass="";
    private String username="";
    private String password="";
    private String message1="";
    public void init() {
    try{
        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        System.out.println("Driver loaded successfully");
       }//close try
    catch (ClassNotFoundException e) {
    System.out.println(e.toString());
    }//close catch
    }//close init() method
    public void doGet(HttpServletRequest request,HttpServletResponse response)throws ServletException, IOException
    } //close doGet
    public void doPost(HttpServletRequest request,HttpServletResponse response)
    throws ServletException, IOException
      user = request.getParameter("username").trim();
      pass = request.getParameter("password").trim();
      System.out.println("*"+user+"*");
      System.out.println("*"+pass+"*");
      String message = null;
    try{
      Connection con= DriverManager.getConnection("jdbc:odbc:MyDS");
      System.out.println("Successfully connected to database");
      PreparedStatement pstmt;
      pstmt = con.prepareStatement("SELECT username,password FROM users" + " WHERE username ='" + user + "'" +
      " AND password='" + pass + "'");
      ResultSet rs = pstmt.executeQuery();
      if(rs.next())
          username = rs.getString(1);
           password = rs.getString(2);     
    if (username != null && password != null && user.equals(username) && pass.equals(password) ){
        message ="ok";
        PrintWriter out = response.getWriter();
        out.print("<B>" + message + "</B>");
        //response.sendRedirect ("http://localhost:8080/thankyou.html");
    }//closes the if statement
    else {
         message="not ok";
         PrintWriter out = response.getWriter();
         out.print("<B>" + message + "</B>");
        //response.sendRedirect ("http://localhost:8080/sampleapp/login.html");
    }//close else statement
    }//closes 2ndtry
    catch (SQLException e) {
    System.out.println(e.toString());
    }//closes 2ndcatch
    }//close doPost
    }//close classKindly let me know ASAP.
    Regarding the database.The fields in the database are "username" and "password" and it has one tuple
    "xyz" and "xyz"
    Hope that my question is rightly put.
    Thanking you
    AS

    Actually, I think the servlet is doing the right thing
    by printing "ok". A quick glance at your code tells
    me that username and password are both members of your
    servlet class and initialized to "". Neither is null,
    and both are blank.
    If your HTML page sends user and pass as blank
    strings, you'll do a database query for those values.
    If they don't appear in the database, your ResultSet
    will have no rows and the username and password data
    members will not be updated.
    When you get to your if test, neither username nor
    password is null and both are equal to the values
    passed in from the HTML. Hence the "ok".
    If you initialize your username and password members
    to null this might still work.
    Be sure to set them back to null when you finish the
    test.
    If you take all that JDBC code out of the servlet and
    isolate it into its own class, you can test it out by
    feeding it valid and invalid username and password
    combinations. Once you've got that working perfectly,
    you can just have the servlet instantiate your
    database object and call its methods. If you have any
    problems after that point, you know they're due to the
    servlet and not the database interactions.
    Right now the database and servlet are confounded.
    Separate them out and you might make faster progress.
    - MODHello,
    Thanks for the reply.Will consider your points for a proper coding.Will keep posting.
    AS

  •   Could somebody help in "how to Connect to database" 

    I'm trying to connect to database and there's a messege appearing tells " ORA-12154: TNS: could not resolve service name", so please if does anybody know how to solve this problem to send me a solution on my email address ( [email protected])........... Thanks

    What client you are using to connect to the database??
    If you are using the database's own client that the above solution works.
    If you are using forms then you must set the tnsnames.ora of the forms that you are using, and not the database's.
    Forms6: %ORACLE_HOME%/Net80/ADMIN/tnsnames.ora
    Forms9 and above: %ORACLE_HOME%/NETWORK/ADMIN/tnsnames.ora
    Or for both cases you can use the net Configuration Assistance provided by Oracle which is a GUI interface of defining TNS Names.
    Regards,
    Tony Garabedian

  • Please help, probleme de connection to database oracle and  java

    Ihave a problem to make connection to database Oracle when I use a simple code of java
    ======================
    import java.sql.*;
    public class Exemple1 {
    public static void main (String args[]) {
    Statement stmt = null;
    Connection con=null;
    try {
    DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
    con = DriverManager.getConnection ("jdbc:oracle:thin:@localhost:1521:GB","scott","tiger");
    catch (Exception e) { System.out.println(e);        }
    =================
    I have :
    * Linux (Fedora core3).
    * Oracle 10g
    My var. environ.:
    * ORACLE_HOME=/u01/app/oracle/product/10.1.0/Db_1
    * PATH=$ORACLE_HOME/bin
    * CLASSPATH=$ORACLE_HOME/jdbc/lib/ojdbc14.jar
    the error is:
    Exception in thread "main" java.lang.NoClassDefFoundError: while resolving class: oracle.sql.CharacterSet
    at java.lang.VMClassLoader.resolveClass(java.lang.Class) (/usr/lib/libgcj.so.5.0.0)
    at java.lang.Class.initializeClass() (/usr/lib/libgcj.so.5.0.0)
    at JvResolvePoolEntry(java.lang.Class, int) (/usr/lib/libgcj.so.5.0.0)
    at oracle.jdbc.driver.DBConversion.DBConversion(short, short, short) (Unknown Source)
    at oracle.jdbc.driver.T4CConnection.connect(java.lang.String, java.util.Properties) (Unknown Source)
    at oracle.jdbc.driver.T4CConnection.logon() (Unknown Source)
    I don't know what's heppen exactly?

    If
    DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
    is replaced
    with
    Class.forName("oracle.jdbc.driver.OracleDriver");does the java.lang.NoClassDefFoundError: while resolving class: oracle.sql.CharacterSet get generated?

  • How to find the number of users  connected to database from OS level(Linux)

    Hi All,
    Could anyone know , how to find the number of users connected to database without connecting with sql*plus
    is there any command to find it?
    example we have 10 databases in one server, how to find the number of users connected to particular database without connecting to database(v$session)?
    oracle version:- 10g,11g
    Operating System:- OEL4/OEL5/AIX/Solaris
    any help will be appreciated.
    Thanks in advance.
    Thank you.
    Regards,
    Rajesh.

    Excellent.
    Tested, works as long as you set the ORACLE_SID first ( to change databases )
    ps -ef | grep $ORACLE_SID | grep "LOCAL=NO" | awk '{print $2}' | wc -l
    Thanks!
    select OSUSER
        from V$SESSION
    where AUDSID = SYS_CONTEXT('userenv','sessionid')
        and rownum=1;Best Regards
    mseberg

  • Taking too much time (1min) to connect to database

    Hi,
    I have oracle 10.2 and 10g application server.
    Its taking too much time to connect to database through application (on browser). The connection through sqlplus is fine.
    Please share your experience.
    Regards,
    Naseer

    Dear AnaTech,
    i am going to ask not related this question which already you answered i am going to ask you about that how to connect forms6i and Developer 10g with OracleAS.
    i have installed and working Developer Suite 10g Ver. 10.1.2 and also Form Builder 6i. On my other machine i installed and working Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 and also on the database machine i installed Oracle Enterprise Manager 10g Application Server Control 10.1.2.0.2.
    my database conectivity with Developer suite Forms and Reports and also Form6i and Reports6i are working fine. no problem.
    now the 1 question of mine is that when i try to run form6i through run from web i got this error. FRM-99999: error 18121 occured see the release not.
    this and the main question of mine is this that how can i control my OracleAS 10g with forms because basically the functionality of OracleAS is Mid-Tier but i am not utilizing the Mid-tier i am using here Two-tier Envrionment even i installed 3-Tier Environment so tell me how i utilize it with 3-Tier..
    I hope you don't mind that i ask this question here and also if you give me you email then we can discuss this in detail and i can be helpful of your great expertise. i also know and utilize my 3-tier real envrionment.
    Waiting for your great response.
    Regards,
    K.J.J.C

  • MySQL Database Connection (two databases at the same time)

    I have never had to open more than one MySQL database from within the same website before, but I do now.  The website I have is designed where all the content comes from within the main database.  I am building an Inventory system that I want within it's own database, in the event I would ever need to move the application to another server or something, I don't want this data residing in the main database.
    Currently, I open the database connection from within a file called "common.php" that resides in a directory called "lib" that can be accessed from the root directory.  Below is the proposed code that would be placed within the "common.php" file:
    // Define Database Variables
    $dbserver = "127.0.0.1";
    $dbuser  = array('clevelan_user1', 'clevelan_user2');
    $dbpass  = array('P@ssw0rd', 'P@ssw0rd2');
    $dbname  = array('clevelan_database1', 'clevelan_database2');
    // Start Session
    session_start();
    // Connect to Databases
    connectdb($dbserver, $dbuser[0], $dbpass[0], $dbname[0]);
    connectdb2($dbserver, $dbuser[1], $dbpass[1], $dbname[1]);
    // Database 1 Connection
    function connectdb($dbserver, $dbuser, $dbpass, $dbname) {
    // connects to db
      global $connection;
      $connection = @mysql_connect($dbserver, $dbuser, $dbpass) or die ("could not connect to server");
      $db = @mysql_select_db($dbname, $connection) or die ("could not select databsase");
      return $connection;
    // Database 2 Connection
    function connectdb2($dbserver, $dbuser, $dbpass, $dbname) {
    // connects to db
      global $connection2;
      $connection2 = @mysql_connect($dbserver, $dbuser, $dbpass) or die ("could not connect to server");
      $db2 = @mysql_select_db($dbname, $connection2) or die ("could not select databsase");
      return $connection2;
    //End of Code Within the "common.php"
    From within any page of the website, I want to access both connections by placing an include at the top of each page:
    include_once("lib/common.php");
    Currently, when I run the code above, any page within the website (the home page) provides error messages with regards to database connectivity (the pages are looking for there content from within the second database.  It's as if the second database is the only database seen by the website.
    I need help figuring out how I can have two MySQL databases open at the same time (the second database will only be open for short periods of time and then closed).  But the main database is always open.

    Create one project using one copy of the exact tables.
    create 2 different sessions.xml files each pointing to the same project. Set the login information in the sessions.xml files.
    That should work fine.
    Peter

  • Enterprise manager is not able to connect to database instance

    Hi
    I am having a problem with Oracle EM. I would appreciate very much if anyone can help me.
    I installed Oracle on XP which runs on virtual pc on XP as well. Everything is fine, I can connect to database with sqlplus, and there were no errors during installation.
    But the problem is that, when I try to connect to database with EM, it says:
    Enterprise manager is not able to connect to database instance . The state of the components are listed below.
    Can anoyone help me?

    user10637311 wrote:
    When you want OEM DB , your existing DB should be created by DBCA or if suppose manually creaed DB then you have to configure that DB to EM by
    "emca -config dbcontrol db -repos create". for these two cases istener should be running.
    emctl start dbconsole -> to start dbconsole service
    emctl status dbconsole-> status of servicesI am sorry, I was looking at $ORACLE_HOME\admin . And in the proper path, both listener.ora and tnsnames.ora do exist.
    emca -config dbcontrol db -repos create :
    <last part>:
    INFO: This operation is being logged at C:\oracle\product\10.2.0\db_1\cfgtoollog
    s\emca\orcl\emca_2010-02-18_02-01-40-AM.log.
    Feb 18, 2010 2:02:46 AM oracle.sysman.emcp.util.DBControlUtil stopOMS
    INFO: Stopping Database Control (this may take a while) ...
    Feb 18, 2010 2:03:19 AM oracle.sysman.emcp.EMReposConfig createRepository
    INFO: Creating the EM repository (this may take a while) ...
    Feb 18, 2010 2:03:19 AM oracle.sysman.emcp.EMReposConfig invoke
    SEVERE: Error creating the repository
    Feb 18, 2010 2:03:19 AM oracle.sysman.emcp.EMReposConfig invoke
    INFO: Refer to the log file at C:\oracle\product\10.2.0\db_1\cfgtoollogs\emca\or
    cl\emca_repos_create_<date>.log for more details.
    Feb 18, 2010 2:03:19 AM oracle.sysman.emcp.EMConfig perform
    SEVERE: Error creating the repository
    Refer to the log file at C:\oracle\product\10.2.0\db_1\cfgtoollogs\emca\orcl\emc
    a_2010-02-18_02-01-40-AM.log for more details.
    Could not complete the configuration. Refer to the log file at C:\oracle\product
    \10.2.0\db_1\cfgtoollogs\emca\orcl\emca_2010-02-18_02-01-40-AM.log for more deta
    ils.
    C:\oracle\product\10.2.0\db_1\cfgtoollogs\emca\or
    cl\emca_repos_create_<date>.log:
    Check if repos user already exists.
    old 6: WHERE username=UPPER('&EM_REPOS_USER');
    new 6: WHERE username=UPPER('SYSMAN');
    old 8: IF ( '&EM_CHECK_TYPE' = 'EXISTS') THEN
    new 8: IF ( 'NOT_EXISTS' = 'EXISTS') THEN
    old 11: raise_application_error(-20000, '&EM_REPOS_USER does not exists..');
    new 11: raise_application_error(-20000, 'SYSMAN does not exists..');
    old 14: ELSIF ( '&EM_CHECK_TYPE' = 'NOT_EXISTS' ) THEN
    new 14: ELSIF ( 'NOT_EXISTS' = 'NOT_EXISTS' ) THEN
    old 17: raise_application_error(-20001, '&EM_REPOS_USER already exists..');
    new 17: raise_application_error(-20001, 'SYSMAN already exists..');
    old 21: raise_application_error(-20002, 'Invalid Check type &EM_CHECK_TYPE');
    new 21: raise_application_error(-20002, 'Invalid Check type NOT_EXISTS');
    DECLARE
    ERROR at line 1:
    ORA-20001: SYSMAN already exists..
    ORA-06512: at line 17

  • Error Connecting to database URL jdbc:oracle:oci:@rmsdbtst as user rms13 java.lang.Exception:UnsatisfiedLinkError encountered when using the Oracle driver

    Trying to Install RMS application 13.2.2 and I get past the pre-installation checks and when I get to the Data Source details and enter the data source details with the check box checked to validate the schema/Test Data Source I get the following error:
    Error Connecting to database URL jdbc:oracle:oci:@rmsdbtst as user rms13 java.lang.Exception:UnsatisfiedLinkError encountered when using the Oracle driver. Please check that the library path is set up properly or switch to the JDBC thin client oracle/jdbc/driver/T2CConnection.getLibraryVersioNumber()
    Checks performed:
    RMS Application code location and directory contents:
    [oracle@test-rms-app application]$ pwd
    /binary_files/STAGING_DIR/rms/application
    [oracle@test-rms-app application]$ ls -ltr
    total 144
    -rw-r--r-- 1 oracle oinstall   272 Dec 7  2010 version.properties
    -rw-r--r-- 1 oracle oinstall   405 Jan 16 2011 expected-object-counts.properties
    -rw-r--r-- 1 oracle oinstall   892 May 13 2011 ant.install.properties.sample
    -rw-r--r-- 1 oracle oinstall 64004 Jun  6  2011 build.xml
    drwxr-xr-x 9 oracle oinstall  4096 Jun 16 2011 rms13
    drwxr-xr-x 3 oracle oinstall  4096 Jun 16 2011 installer-resources
    drwxr-xr-x 3 oracle oinstall  4096 Jun 16 2011 antinstall
    drwxr-xr-x 2 oracle oinstall  4096 Jun 16 2011 ant-ext
    drwxr-xr-x 5 oracle oinstall  4096 Jun 16 2011 ant
    -rw-r--r-- 1 oracle oinstall 11324 Dec 18 09:18 antinstall-config.xml.ORIG
    -rwxr-xr-x 1 oracle oinstall  4249 Dec 18 10:01 install.sh
    drwxr-xr-x 4 oracle oinstall  4096 Dec 18 10:06 common
    -rw-r--r-- 1 oracle oinstall 16244 Dec 19 10:37 antinstall-config.xml
    -rw-r--r-- 1 oracle oinstall   689 Dec 19 10:37 ant.install.log
    [oracle@test-rms-app application]$
    Application installation:
    [oracle@test-rms-app application]$ ./install.sh
    THIS IS the driver directory
    Verified $ORACLE_SID.
    Verified SQL*Plus exists.
    Verified write permissions.
    Verified formsweb.cfg read permissions.
    Verified Registry.dat read permissions.
    Verified Java version 1.4.2.x or greater. Java version - 1.6.0
    Verified Tk2Motif.rgb settings.
    Verified frmcmp_batch.sh status.
    WARNING: Oracle Enterprise Linux not detected.  Some components may not install properly.
    Verified $DISPLAY - 172.16.129.82:0.0.
    This installer will ask for your "My Oracle Support" credentials.
    Preparing installer. This may take a few moments.
    Your internet connection type is: NONE
    Integrating My Oracle Support into the product installer workflow...
         [move] Moving 1 file to /binary_files/STAGING_DIR/rms/application
    Installer preparation complete.
    MW_HOME=/u01/app/oracle/Middleware/NewMiddleware1034
    ORACLE_HOME=/u01/app/oracle/Middleware/NewMiddleware1034/as_1
    ORACLE_INSTANCE=/u01/app/oracle/Middleware/NewMiddleware1034/asinst_1
    DOMAIN_HOME=/u01/app/oracle/Middleware/NewMiddleware1034/user_projects/domains/rmsClassDomain
    WLS_INSTANCE=WLS_FORMS
    ORACLE_SID=rmsdbtst
    JAVA_HOME=/u01/app/oracle/jrockit-jdk1.6.0_45-R28.2.7-4.1.0
    Launching installer...
    To make sure I have connectivity from the app server to the database (on a database server) here are the steps followed:
    [oracle@test-rms-app application]$ tnsping rmsdbtst
    TNS Ping Utility for Linux: Version 11.1.0.7.0 - Production on 19-DEC-2013 10:41:40
    Copyright (c) 1997, 2008, Oracle.  All rights reserved.
    Used parameter files:
    Used TNSNAMES adapter to resolve the alias
    Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = test-rms-db.vonmaur.vmc)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SID = rmsdbtst)))
    OK (0 msec)
    [oracle@test-rms-app application]$
    [oracle@test-rms-app application]$ sqlplus rms13@rmsdbtst
    SQL*Plus: Release 11.1.0.7.0 - Production on Thu Dec 19 10:46:18 2013
    Copyright (c) 1982, 2008, Oracle.  All rights reserved.
    Enter password:
    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
    SQL> exit
    Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
    [oracle@test-rms-app application]$
    [oracle@test-rms-app application]$ ping test-rms-db
    PING test-rms-db.vonmaur.vmc (192.168.1.140) 56(84) bytes of data.
    64 bytes from test-rms-db.vonmaur.vmc (192.168.1.140): icmp_seq=1 ttl=64 time=0.599 ms
    64 bytes from test-rms-db.vonmaur.vmc (192.168.1.140): icmp_seq=2 ttl=64 time=0.168 ms
    64 bytes from test-rms-db.vonmaur.vmc (192.168.1.140): icmp_seq=3 ttl=64 time=0.132 ms
    64 bytes from test-rms-db.vonmaur.vmc (192.168.1.140): icmp_seq=4 ttl=64 time=0.158 ms
    64 bytes from test-rms-db.vonmaur.vmc (192.168.1.140): icmp_seq=5 ttl=64 time=0.135 ms
    --- test-rms-db.vonmaur.vmc ping statistics ---
    5 packets transmitted, 5 received, 0% packet loss, time 4001ms
    rtt min/avg/max/mdev = 0.132/0.238/0.599/0.181 ms
    [oracle@test-rms-app application]$
    [oracle@test-rms-app application]$ uname -a
    Linux test-rms-app.vonmaur.vmc 2.6.18-128.el5 #1 SMP Wed Jan 21 08:45:05 EST 2009 x86_64 x86_64 x86_64 GNU/Linux
    [oracle@test-rms-app application]$
    [oracle@test-rms-app application]$ cat /etc/*-release
    Enterprise Linux Enterprise Linux Server release 5.3 (Carthage)
    Red Hat Enterprise Linux Server release 5.3 (Tikanga)
    [oracle@test-rms-app application]$
    The database is created and all the batch file scripts have been successfully deployed.  Now working on the application server.  The  Weblogic server is installed and 11g forms and reports are installed successfully.
    Any help would be helpful.
    Thanks,
    Ram.

    Please check MOS Notes:
    FAQ: RWMS 13.2 Installation and Configuration (Doc ID 1307639.1)

  • Error while connecting MYSQL Database

    Hi,
    I use a 30 days trial of Crystal Reports 2008. When i try to connect with the database i always get the next error: [http://www.visiscan.nl/error.jpg]
    The database is 4.1GB large and there is 10GB free space on the database.
    Anybody can tell me what to do?

    Hi Tom,
    As I understand the error while connecting to database is
    u201CFailed to retrieve data from databaseu201D
    There could be some could be multiple reasons for this.
    If you are using an ODBC connection then try to check the DSN. Recreate the same and then try.
    If the database is oracle check if native client is installed and try to ping from the native client to check if it responds.
    When connecting to Oracle, ensure that the Service name is identical to that used in the <ORA_HOME>/network/admin/tnsnames.ora file on the BusinessObjects XI Release 2 server.
    For ODBC databases, ensure that the ODBC DSN is exactly the same in the ODBC Manager as on the BusinessObjects XI Release 2 server.
    Please let us know if this helps
    Regards,
    Aditya Joshi

Maybe you are looking for