Having trouble writing to a database although SQL query is correct

Hi there. I am trying to write an sql query to a database but I am failing to understand what is going wrong in terms of executing the query.
I have the following code.
static public int writeToStockTable (String suppIn, String nameIn, String typeIn, float quantIn, float priceIn, String descIn, String styleIn, String finishIn)         {               // Temporary variable to hold the SQL query               String SQLString, SQLString2;               ResultSet rs = null;                                     // Build a string containing the SQL INSERT instruction to be used later             SQLString = "INSERT INTO "+typeIn+" VALUES ('1', '" + suppIn + "', '" + nameIn + "', " + quantIn + ", " + priceIn + ", '"+descIn+"', '"+styleIn+"', '"+finishIn+"')";             SQLString2 = "SELECT Name FROM Suppliers WHERE Name = '" + suppIn + "'";                                         try                   {                         // The createStatement() method creates a Statement object.  Object will be                         // attached to my reference variable (statement) defined at the top of class.                         statement = connectionToBellFiresDB.createStatement();                                                 // The executeUpdate() statement can be used here to execute an                         // SQL INSERT instruction.                         rs = statement.executeQuery (SQLString2);                         if ((rs == null))                         {                             System.out.println ("Trying to say no supplier");                             return (-2);                         }                                                 else                         {                             System.out.println (SQLString);                             statement.executeUpdate (SQLString);                         }                                           }                 catch (SQLException exception)                   {                       return (-1);    // Return -1 if problem writing record to file                   }                             return (0);  // Return with 0 if record successfully written                       }
Please ignore the attributes not used, it is very much a work in progress. The command that prints SQLString prints
INSERT INTO Fireplace VALUES ('1', 'a', 'a', 1.0, 1.0, 'a', 'a', 'a')
which is correct, but will return the error code -1 when asked to execute the query. The database jdbc:odbc driver has been initialised in the control panel and the program has no other problems accessing the database as far as i am aware.
Any help would be appreciated, i hate database connections :)

Chrift wrote:
Im sorry i dont know what you mean by eating the exception, im quite a noob at programming to be honest!
How do i print it out and what is a stack trace?Do you know what an exception is? If not, then you should stay far away from JDBC/Database programming for the time being.
Read [the Exception Tutorial|http://java.sun.com/docs/books/tutorial/essential/exceptions/] first.
Then: an exception has quite a bit of useful information attached that tells you what went wrong.
In your case you catch the exception and ignore everything it could tell you by simply returning -1. Returning 0 and -1 to indicate success/failure is a very bad idea and should not be used in Java code, it's a C-style convention for C-era programming languages. In Java you use exceptions instead.
For starters you could simply add "exception.printStackTrace()" in your catch-block to get some more information out of the exception.

Similar Messages

  • I'm having trouble writing a polynomial code.

    I'm having trouble with a polynomial code I'm supposed to conjour it. It's simply a code that adds, subtracts, and multiplies polynomials. However, there are a few methods I do not know how to come up with (I left them blank), and when I test the code write now, it doesn't work. Here's the code -- can anyone help?
    public class Polynomial implements Cloneable {
         private int m_degree;
         private double[] m_coefficient;
         // This is the default constructor
         public Polynomial() {
              super();
              m_degree = 0;
              m_coefficient = new double[5];
         // This allows the user to build a polynomial by putting a constant in
         public Polynomial(double constant) {
              this();
              m_coefficient[0] = constant;
         public Polynomial(Polynomial source) {
         // These are the getters
         public double getCoefficient(int degree) {
              return m_coefficient[degree];
         public int getDegree() {
              return m_degree;
         // These are the setters
         public void addToCoefficient(double amount, int degree) {
              m_coefficient[degree] += amount;
         public void assignCoefficient(double newCoefficient, int degree) {
              m_coefficient[degree] = newCoefficient;
         public void clear() {
              for (int i = 0; i < m_coefficient.length; i++) {
                   m_coefficient[i] = 0;
         public void reserve(int degree) {
         // These are other, useful methods
         public int nextTerm(int k) {
              int value = 0;
              return value;
         public double eval(double x) {
              double value = 0;
              // This goes through all the exponents in the polynomial
              for (int i = 0; i < getDegree(); i++) {
                   // += allows you to add instead of overriding the next term
                   value += getCoefficient(i) * Math.pow(x, i);
              return value;
         // Here is our addition method
         public static Polynomial add(Polynomial p1, Polynomial p2) {
              Polynomial newPolynomial = new Polynomial();
              // We have to find the bigger polynomial so we know how to set the loop
              if (p1.getDegree() >= p2.getDegree()) {
                   for (int i = 0; i < p1.getDegree(); i++) {
                        newPolynomial.addToCoefficient(p1.getCoefficient(i)
                                  + p2.getCoefficient(i), i);
              } else {
                   for (int i = 0; i < p2.getDegree(); i++) {
                        newPolynomial.addToCoefficient(p1.getCoefficient(i)
                                  + p2.getCoefficient(i), i);
              return newPolynomial;
         // Here is our subtraction method
         public static Polynomial subtract(Polynomial p1, Polynomial p2) {
              Polynomial newPolynomial = new Polynomial();
              // We have to find the bigger polynomial so we know how to set the loop
              if (p1.getDegree() >= p2.getDegree()) {
                   for (int i = 0; i < p1.getDegree(); i++) {
                        newPolynomial.addToCoefficient(p1.getCoefficient(i)
                                  - p2.getCoefficient(i), i);
              } else {
                   for (int i = 0; i < p2.getDegree(); i++) {
                        // The order is important with subtraction so they cannot be
                        // switched
                        // The equation is allowed to be negative, but the exponent
                        // cannot be
                        newPolynomial.addToCoefficient(p1.getCoefficient(i)
                                  - p2.getCoefficient(i), i);
              return newPolynomial;
         // Here is our multiplication method
         public static Polynomial multiply(Polynomial p1, Polynomial p2) {
              Polynomial newPolynomial = new Polynomial();
              if (p1.getDegree() >= p2.getDegree()) {
                   for (int i = 0; i < p1.getDegree(); i++) {
                        newPolynomial.addToCoefficient(p1.getCoefficient(i)
                                  * p2.getCoefficient(i), i);
              } else {
                   for (int i = 0; i < p2.getDegree(); i++) {
                        newPolynomial.addToCoefficient(p1.getCoefficient(i)
                                  * p2.getCoefficient(i), i);
              return newPolynomial;
         // Here is our clone method
         public Polynomial clone() {
              Polynomial poly;
              try {
                   poly = (Polynomial) super.clone();
              } catch (CloneNotSupportedException e) {
                   throw new RuntimeException(
                             "Class does not implement cloneable interface");
              return poly;
    }

    We've been working with arrays, and we have to write a code that adds, subtracts, and multiplies polynomials. I'm having trouble with a few of the methods. I've assigned m_degree and m_coefficient as the fields I need to use.
    Right now, as my code stands, when I test it with a polynomial in main, it doesn't work. So right now, there's a mistake preventing what I have so far from properly functioning.
    I am also having trouble writing the following methods:
    reserve: We have to allocate memory to the polynomial every time it changes so we make sure we always have enough space to work with it.
    nextTerm: We need this to jump to the next term in the polynomial, but I'm not quite sure how to do it. I didn't even realize it was possible.
    I'm horrible at commenting and explaining my code, but if you read over it just a little bit, you may be able to get the gist of what I'm trying to do. Thanks for any help, and sorry if I can't explain well.
    public class Polynomial implements Cloneable {
    private int m_degree;
    private double[] m_coefficient;
    // This is the default constructor
    public Polynomial() {
    super();
    m_degree = 0;
    m_coefficient = new double[5];
    // This allows the user to build a polynomial by putting a constant in
    public Polynomial(double constant) {
    this();
    m_coefficient[0] = constant;
    public Polynomial(Polynomial source) {
    // These are the getters
    public double getCoefficient(int degree) {
    return m_coefficient[degree];
    public int getDegree() {
    return m_degree;
    // These are the setters
    public void addToCoefficient(double amount, int degree) {
    m_coefficient[degree] += amount;
    public void assignCoefficient(double newCoefficient, int degree) {
    m_coefficient[degree] = newCoefficient;
    public void clear() {
    for (int i = 0; i < m_coefficient.length; i++) {
    m_coefficient[i] = 0;
    public void reserve(int degree) {
    // These are other, useful methods
    public int nextTerm(int k) {
    int value = 0;
    return value;
    public double eval(double x) {
    double value = 0;
    // This goes through all the exponents in the polynomial
    for (int i = 0; i < getDegree(); i++) {
    // += allows you to add instead of overriding the next term
    value += getCoefficient(i) * Math.pow(x, i);
    return value;
    // Here is our addition method
    public static Polynomial add(Polynomial p1, Polynomial p2) {
    Polynomial newPolynomial = new Polynomial();
    // We have to find the bigger polynomial so we know how to set the loop
    if (p1.getDegree() >= p2.getDegree()) {
    for (int i = 0; i < p1.getDegree(); i++) {
    newPolynomial.addToCoefficient(p1.getCoefficient(i)
    + p2.getCoefficient(i), i);
    } else {
    for (int i = 0; i < p2.getDegree(); i++) {
    newPolynomial.addToCoefficient(p1.getCoefficient(i)
    + p2.getCoefficient(i), i);
    return newPolynomial;
    // Here is our subtraction method
    public static Polynomial subtract(Polynomial p1, Polynomial p2) {
    Polynomial newPolynomial = new Polynomial();
    // We have to find the bigger polynomial so we know how to set the loop
    if (p1.getDegree() >= p2.getDegree()) {
    for (int i = 0; i < p1.getDegree(); i++) {
    newPolynomial.addToCoefficient(p1.getCoefficient(i)
    - p2.getCoefficient(i), i);
    } else {
    for (int i = 0; i < p2.getDegree(); i++) {
    // The order is important with subtraction so they cannot be
    // switched
    // The equation is allowed to be negative, but the exponent
    // cannot be
    newPolynomial.addToCoefficient(p1.getCoefficient(i)
    - p2.getCoefficient(i), i);
    return newPolynomial;
    // Here is our multiplication method
    public static Polynomial multiply(Polynomial p1, Polynomial p2) {
    Polynomial newPolynomial = new Polynomial();
    if (p1.getDegree() >= p2.getDegree()) {
    for (int i = 0; i < p1.getDegree(); i++) {
    newPolynomial.addToCoefficient(p1.getCoefficient(i)
    * p2.getCoefficient(i), i);
    } else {
    for (int i = 0; i < p2.getDegree(); i++) {
    newPolynomial.addToCoefficient(p1.getCoefficient(i)
    * p2.getCoefficient(i), i);
    return newPolynomial;
    // Here is our clone method
    public Polynomial clone() {
    Polynomial poly;
    try {
    poly = (Polynomial) super.clone();
    } catch (CloneNotSupportedException e) {
    throw new RuntimeException(
    "Class does not implement cloneable interface");
    return poly;
    }

  • Issue in creation of group in oim database through sql query.

    hi guys,
    i am trying to create a group in oim database through sql query:
    insert into ugp(ugp_key,ugp_name,ugp_create,ugp_update,ugp_createby,ugp_updateby,)values(786,'dbrole','09-jul-12','09-jul-12',1,1);
    it is inserting the group in ugp table but it is not showing in admin console.
    After that i also tried with this query:
    insert into gpp(ugp_key,gpp_ugp_key,gpp_write,gpp_delete,gpp_create,gpp_createby,gpp_update,gpp_updateby)values(786,1,1,1,'09-jul-12',1,'09-jul-12',1);
    After that i tried with this query.but still no use.
    and i also tried to assign a user to the group through query:
    insert into usg(ugp_key,usr_key,usg_priority,usg_create,usg_update,usg_createby,usg_updateby)values(4,81,1,'09-jul-12','09-jul-12',1,1);
    But still the same problem.it is inserting in db.but not listing in admin console.
    thanks,
    hanuman.

    Hanuman Thota wrote:
    hi vladimir,
    i didn't find this 'ugp_seq'.is this a table or column?where is it?
    It is a sequence.
    See here for details on oracle sequences:
    http://www.techonthenet.com/oracle/sequences.php
    Most of the OIM database schema is created with the following script, located in the RCU distribution:
    $RCU_HOME/rcu/integration/oim/sql/xell.sql
    there you'll find plenty of sequence creation directives like:
    create sequence UGP_SEQ
    increment by 1
    start with 1
    cache 20
    to create a sequence, and
    INSERT INTO UGP (UGP_KEY, UGP_NAME, UGP_UPDATEBY, UGP_UPDATE, UGP_CREATEBY, UGP_CREATE,UGP_ROWVER, UGP_DATA_LEVEL, UGP_ROLE_CATEGORY_KEY, UGP_ROLE_OWNER_KEY, UGP_DISPLAY_NAME, UGP_ROLENAME, UGP_DESCRIPTION, UGP_NAMESPACE)
    VALUES (ugp_seq.nextval,'SYSTEM ADMINISTRATORS', sysadmUsrKey , SYSDATE,sysadmUsrKey , SYSDATE, hextoraw('0000000000000000'), 1, roleCategoryKey, sysadmUsrKey, 'SYSTEM ADMINISTRATORS', 'SYSTEM ADMINISTRATORS', 'System Administrator role for OIM', 'Default');
    as a sequence usage example.
    Regards,
    Vladimir

  • To dear apple FaceTime users  I'm having troubles logging on to FaceTime I typed in my correct details and its saying check network connection. I did that and every things fine. Any ideas?

    To dear apple FaceTime users
    I'm having troubles logging on to FaceTime I typed in my correct details and its saying check network connection. I did that and every things fine. Any ideas?

    Hello...i'm new to forums....was there ever a solution to this problem please?

  • Having trouble mapping multiple Informix databases to Oracle

    Hello,
    I am new to Oracle, so please forgive any misuse of Oracle terminology.
    I have several dozen Informix 7.31 databases to migrate to Oracle.
    We host more than one database per Informix server instance.
    Each of these databases have the same schema definition and are usually created by the same user. So, since the table names and owner names are the same for more than one database, the database name itself is the only unique value.
    When I attempt to use the Migration Workbench, the database name is lost. The Oracle model created seems to be merging several Informix databases into a single Oracle database (or schema).
    A very brief example involving 2 tables;
    Informix Source: Database: alf owner: padb table: device_config
    Database: firstlast owner: padb table: device_config
    Oracle Model: Database: padb User: padb
    Table: device_config and device_config_1
    I thought I might be able to modify the Informix source database so that the owner name was the same as the database name. That is not always possible because Informix has a limit of 8 characters for user names and many of the Informix database names are longer than that.
    This will not work at all. I really don't want to set up separate database server instance for each schema. I found the following statement in one of the Oracle manuals:
    "A schema is owned by a database user and has the same name as that user. Each user owns a single schema."
    Please help me figure out how to do this.

    Do you want to keep all of these Informix databases seperate?Yes, if I understand the question correctly. If this is a question about disk amangement, I am not very concerned with that at this point. I plan to worry about optimizing IO later.
    Are all of these databases the same or different? e.g. is the definition of device_config the same for all databases?All the databases have the exact same schema definitions.
    Do you need more than one instance of Oracle? e.g. dev / qa / production?There will be more than one instance, but that is based on region and load. Eventually there will be servers deployed throuout the world and serveral sites. Some sites have more than one server, others only have one.
    You are correct that I have a lot more reading to do.
    The application that uses these databases currently works like this;
    1) A DSN Data Source is selected from a list. (it is assumed that each DSN is a separare instance)
    2) A connection is opened and a list of databases/schemas is queried from the system catalog.
    3) The user selects the database to work with.
    Thanks for your help,
    Rob

  • Database - Show SQL Query question..

    Greetings:
        I am helping a co-worker with Crystal. I don't use crystal but I am able to explain the problem. My co worker is currently using crystal reports 8.5. If he pulls a query and the report is generated he can then click on Database menu then click on Show SQL Query. From there he is able to edit, add, remove fields. Now we want to place him on Crystal V10. When he does the same task, instead of being able to edit the Show SQL query he can only view it. Is there a way around this so that he can Edit the sql query in version 10 or did that feature go away in versions 9 and above. Also we are going to Purchase Crystal 2008, is this feature available in 08? Any help would be appreicated..

    Hi there!
    I have the same problem as described above.  I have been asked to figure out what is wrong with one of the reports that used to work when we used MAS 4.05.  We are now on MAS 4.20 with Crystal Reports v.10 and the report fails to run.  I loaded the report into Crystal to see if I could see the problem and I discovered that the report is still trying to access a table from the old MAS database.  The SQL code as shown in the Show SQL Query window is as follows:
    SELECT "AR_InvoiceHistoryHeader"."InvoiceNo", "AR_InvoiceHistoryDetail"."ItemCodeDesc", "AR_InvoiceHistoryDetail"."ItemCode", "AR_InvoiceHistoryDetail"."ExtensionAmt"
    FROM   "AR_InvoiceHistoryHeader" "AR_InvoiceHistoryHeader", "AR_InvoiceHistoryDetail" "AR_InvoiceHistoryDetail"   
    WHERE  "AR_InvoiceHistoryHeader"."InvoiceNo"="AR_InvoiceHistoryDetail"."InvoiceNo" AND "AR_InvoiceHistoryHeader"."HeaderSeqNo"="AR_InvoiceHistoryDetail"."HeaderSeqNo" AND "AR_InvoiceHistoryHeader"."CommissionAmt"="AR_InvoiceHistoryDetail"."CommissionAmt" AND      ARO_InvHistoryDetail."SOItemNumber" <> 'COMMENT' AND      ARN_InvHistoryHeader."InvoiceDate" = {d '2007-09-21'}  
    ORDER BY "AR_InvoiceHistoryHeader"."InvoiceNo"
    The problem is that ARN_InvHistoryHeader needs to be AR_InvoiceHistoryHeader and SOItemNumber needs to be ItemCode.
    When I go into the Database Expert, I can only see the tables in the FROM clause.  I don't know how to modify the WHERE clause.  It kind of looks like this report was only partially converted to the new version.  Is there a way to changed these attributes without rebuilding the whole report?
    By the way, I apologize for not setting my SQL off in a code box, but I tried that and it caused the page to be very wide with no horizontal scroll bar.
    Edited by: Jason Schill on Oct 27, 2008 11:30 PM

  • Trouble referencing BI Publisher parameters in SQL Query (nQSError: 46033)

    Hello everyone,
    I have a query that references some Parameters I created in BI Publisher. They are:
    grade_var of type String
    school_var of type String
    school_year of type String
    The SQL used to for the data model of the report is:
    SELECT "KW School Year"."School Year", "KW Grade"."Grade Seq Nbr", "KW Grade"."Grade Desc", "KWC Enrolment"."Student Count", +(case WHEN "KW School"."School Name" = 'Campbell Collegiate' then "KW School"."School Name" else 'Z - Other School' end)+
    FROM "Sask DW"
    WHERE ("KW Student"."Student Nbr" IN
    (SELECT "KW Student"."Student Nbr"
    FROM "Sask DW"
    WHERE ("KW School"."Post Secondary Institute Ind" = 'N')
    AND ("KW Enrolment Outcome"."Enrolment Outcome" NOT IN ('Deceased', 'Transferred to out-of-country schooling', 'Transferred to out-of-province schooling'))
    AND ("KW Grade"."Grade Desc" = :grade_var)
    AND ("KW School"."School Name" = :school_var)
    AND ("KW School Year"."School Year" = :school_year_var)) )
    AND ("KW School"."Post Secondary Institute Ind" = 'N')
    AND ("KW Enrolment Outcome"."Enrolment Outcome" NOT IN ('Deceased', 'Transferred to out-of-country schooling', 'Transferred to out-of-province schooling'))
    AND +("KW School Year"."School Year" >= '2005/2006')+
    The above query works great and I can get back results and throw them into a template and it works great. The problem comes when I want to change what is highlighted in italics text. School Name and School Year values are hard coded into the SQL but I want those to reference the value of the BI Publisher parameter. It seems to work fine in the bolded part but when I put the paramater name into the italics part, I get the error message:
    java.io.IOException: prepare query failed[nQSError: 46033] Datatype: 25 is not supported.
    The query I am trying to submit is (changes highlighted in bold):
    SELECT "KW School Year"."School Year", "KW Grade"."Grade Seq Nbr", "KW Grade"."Grade Desc", "KWC Enrolment"."Student Count", *(case WHEN "KW School"."School Name"=:school_var then "KW School"."School Name" else 'Z - Other School' end)*
    FROM "Sask DW"
    WHERE ("KW Student"."Student Nbr" IN
    (SELECT "KW Student"."Student Nbr"
    FROM "Sask DW"
    WHERE ("KW School"."Post Secondary Institute Ind" = 'N')
    AND ("KW Enrolment Outcome"."Enrolment Outcome" NOT IN ('Deceased', 'Transferred to out-of-country schooling', 'Transferred to out-of-province schooling'))
    AND ("KW Grade"."Grade Desc" = :grade_var)
    AND ("KW School"."School Name" = :school_var)
    AND ("KW School Year"."School Year" = :school_year_var)) )
    AND ("KW School"."Post Secondary Institute Ind" = 'N')
    AND ("KW Enrolment Outcome"."Enrolment Outcome" NOT IN ('Deceased', 'Transferred to out-of-country schooling', 'Transferred to out-of-province schooling'))
    AND ("KW School Year"."School Year" >= :school_year_var)
    The parameters are all of type string and all the columns I am comparing them to are VARCHAR. What doesn't make sense is that the parameters can be compared to the columns in the middle of the SQL but when I try a similar comparison near the beginning and at the end, I get the error shown above.
    Any thoughts/tips?
    Thanks!
    Edited by: jmoe316 on Oct 21, 2009 9:43 AM
    Edited by: jmoe316 on Oct 21, 2009 9:49 AM

    Hi Jared,
    Did you have any success with the syntax suggested? I am having the same issue and would like to know if using the parameter as part of the SQL query select statement is feasible. The goal is to have a column dynamically selected based on a parameter value. My example:
    SELECT
    CASE
    WHEN :p_name = 'Joe' THEN table1.column_a
    WHEN :p_name = 'Tom' THEN table1.column_b
    ELSE table1.column_c
    END
    FROM ...
    Regards
    Edited by: user11929404 on Mar 14, 2011 1:18 PM
    Edited by: user11929404 on Mar 14, 2011 1:20 PM

  • How to backup database using sql query?

    Hello,i'm student, i'm researching oracle database,i want to backup database that using sql query (like backup query in SQL SERVER) ,how to do that ??
    Thank!

    No, database backups cannot be done from within the database.
    Commands for backups are outside of the database.
    See the "2 Day DBA Guide" http://download.oracle.com/docs/cd/E11882_01/server.112/e10897/toc.htm
    and the "Backup and Recovery Users's (actually Adminsitrator's) Guide : http://download.oracle.com/docs/cd/E11882_01/backup.112/e10642/toc.htm
    Hemant K Chitale

  • Having trouble communicating with ipod says software was not installed correctly and then asks if i want it repaired but couldnt need help

    Having trouble communicating with i pod says software was not installed correctly and asks if i want it repaired but then says could not be repaired.Installed uninstalled numerous times but nothing dont know what else to do.

    See the second box of  Troubleshooting issues with iTunes for Windows updates.
    tt2

  • I am having trouble signing in to iMessage. I enter the correct email and password but keeps saying to retry in a few moments. Please help!

    I have recently restored my iPod touch by computer and am having trouble signing in to my Apple ID for messages and Facetime. I enter the correct email and password but keeps saying that it is a network error.

    try
    FaceTime, Game Center, Messages: Troubleshooting sign in issues

  • Having trouble writing server side code

    I have installed FMS 3.5 (by download from Adobe's site)
    I am trying to develop a simple chat application. It's quite strange that why the following error is producing
    main.asc: line 4: SyntaxError: missing ; before statement: var __CONFIG__.isConfigLoaded = false;
    The first few lines look like this
    ==========================================
    load( "components.asc" );
    var __CONFIG__ = new Object();
    var __CONFIG__.isConfigLoaded = false;
    ==========================================
    if I remove the "var" (AS1 style?) then it does not report any error. Can somebody please help me?
    Kind Regards
    Rakesh

    You're attempting to write AS3 on FMS and it doesn't have any Flash Style AS interpreter for script.  It's plain Javascript as provided by the Mozilla Spidermonkey engine.  I recommend checking out the docs - particularly the Server Side Actionscript Guide.  That should help.
    A

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

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

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

  • I have been thrilled to use file sharing for tv programs on my home pc and watch on the ipad, i am having trouble finding out how to sort programs in any correct order, any help?

    I have been thrilled to use file sharing for tv programs downloaded on my home pc.  I have not been able to sort the program list on the ipad2 to make the list appear in order of showtime or live appearence.  Any suggestions?

    I have been thrilled to use file sharing for tv programs downloaded on my home pc.  I have not been able to sort the program list on the ipad2 to make the list appear in order of showtime or live appearence.  Any suggestions?

  • ORA-00935:  group function is nested too deeply - SQL Query is correct...

    select s.sname, to_char(sum(t.amount), 'fm$999999.00')
    from transactions t, salespeople s
    where t.sid = s.sid
    group by s.sname, t.year
    having (t.year = 1997) and max(sum(t.amount));
    I'm trying to print sales person name who had the highest total sell in 1997. I do not see where did i go wrong in the above query...Isn't nested group function allowed?!
    What about this?
    select s.sname, to_char(sum(t.amount), 'fm$999999.00') as "TOTAL"
    from transactions t, salespeople s
    where t.sid = s.sid
    group by s.sname, t.year
    having (t.year = 1997) and sum(t.amount) = (select max(amount) from transactions where year = 1997);
    It should return something, but it does not due lack of data in database. I think the above code is correct. I just need to confirm from you...

    select s.sname, (case when sum(t.amount) > sum(t2.amount)
    then sum(t.amount)
    else sum(t2.amount)
    end) "TOTAL"
    from transactions t, salespeople s
    where t.sid = s.sid
    group by s.sname, t.year
    having t.year = 1997
    union
    select s.sname, sum(t2.amount)
    from transactions t2, salespeople s
    where t2.sid = s.sid
    group by s.sname, t2.year
    having t2.year = 1997;
    Your code looks good, but it does not work in Oracle Developer...
    The above should work isn't it? The inner query gets executed then the outer one so the result i get in

  • SQL query to correct the corrupted data

    Hi All,
    I got strucked up with a query correcting the corrupted records.
    CREATE TABLE EX1
    EMPID INTEGER,
    DW_EFF_DT DATE,
    DW_EXPR_DT DATE
    INSERT INTO EX1 VALUES(1,'04-MAR-1998','13-MAR-1999');
    INSERT INTO EX1 VALUES(1,'14-MAR-1999','02-MAY-2000');
    INSERT INTO EX1 VALUES(1,'03-MAY-2000','01-MAY-2013');
    INSERT INTO EX1 VALUES(1,'02-MAY-2013','31-DEC-9999');
    I have empid with other attributes,we are maintaing history.There is some data which is corrupted and we need to correct it.
    DW_EFF_DT which is less than '01-FEB-2005' should be made by default '31-JAN-2005'
    Again the data should be corrected and my output should be like the below
    EMPNO     DW_EFF_DT     DW_EXPR_DT
    1     2005-01-27     2005-01-28
    1     2005-01-29     2005-01-30
    1     2005-01-31     2013-05-01
    1     2013-05-02     9999-12-31
    I used the lead and lag function,but it is applied sequentially.
    How I can get the dates subtratcing by 1 for each and every alternative row.
    I tried the below query and able to achive half of it.
    SELECT A.* ,COALESCE(LEAD(NEW_DW_EFF,1) OVER(ORDER BY NEW_DW_EFF) -1,TO_DATE('31-DEC-9999','DD-MON-YYYY')) AS NEW_DW_EXPR_DT
    FROM
    SELECT ID,
    DW_EFF_DT,
    DW_EXPR_DT,
    CASE WHEN DW_EFF_DT<TO_DATE('01-FEB-2005','DD-MON-YYYY') THEN TO_DATE('31-JAN-2005','DD-MON-YYYY') ELSE DW_EFF_DT END AS NEW_DW_EFF
    FROM EX1
    )A
    ID     DW_EFF_DT     DW_EXPR_DT     NEW_DW_EFF     NEW_DW_EXPR_DT
    1     04-MAR-98     13-MAR-99      31-JAN-05      30-JAN-05
    1     14-MAR-99     02-MAY-00      31-JAN-05      30-JAN-05
    1     03-MAY-00      01-MAY-13      31-JAN-05      01-MAY-13
    1     02-MAY-13      31-DEC-99      02-MAY-13      31-DEC-99
    Please help me in this regard.i am still trying it.
    Thanks in advance,
    KVB

    KVB wrote:
    EMPNO     DW_EFF_DT     DW_EXPR_DT
    1     2005-01-27     2005-01-28
    1     2005-01-29     2005-01-30
    1     2005-01-31     2013-05-01
    1     2013-05-02     9999-12-31
    Actually the last record is the active record.
    Th 3rd record effectiuve date is adjusted because the dateis less than 2005-02-01. So that we adjusted to 2005-01-31,
    The 2nd record expiry date will be adjusted to 3rd record effective date-1,
    Now the 2nd record effective will be adjusted to 2nd record expiry date-1 and so on..until the first record.
    Actually I could not explain much better in business point of view like why they do this.Technically we need to achive this through SQL.
    CheersOkay, that makes more sense, thanks :)
    Probably not the prettiest ... but should work (you may need to tweak it a bit)
    ME_TUBBZ? select
      2        empid
      3     ,  to_date('2005-02-01','yyyy-mm-dd')  - ( 2* rn) + 1 as new_eff_date
      4     ,  case
      5           when rn = 1
      6           then
      7              dw_expr_dt
      8           else
      9              to_date('2005-02-01','yyyy-mm-dd') - (2 * (rn - 1))
    10        end
    11              as new_exp_date
    12     ,  dw_eff_dt
    13     ,  dw_expr_dt
    14  from
    15  (
    16     select
    17           empid
    18        ,  dw_eff_dt
    19        ,  dw_expr_dt
    20        ,  row_number() over (partition by empid order by dw_eff_dt desc)             as rn
    21     from ex1
    22     where dw_eff_dt < to_date('2005-02-01','yyyy-mm-dd')
    23  )
    24  order by dw_eff_dt  asc
    25  /
                 EMPID NEW_EFF_DATE         NEW_EXP_DATE         DW_EFF_DT            DW_EXPR_DT
                     1 27-JAN-2005 00 00:00 28-JAN-2005 00 00:00 04-MAR-1998 00 00:00 13-MAR-1999 00 00:00
                     1 29-JAN-2005 00 00:00 30-JAN-2005 00 00:00 14-MAR-1999 00 00:00 02-MAY-2000 00 00:00
                     1 31-JAN-2005 00 00:00 01-MAY-2013 00 00:00 03-MAY-2000 00 00:00 01-MAY-2013 00 00:00
    3 rows selected.
    Elapsed: 00:00:00.01
    ME_TUBBZ? Cheers,

Maybe you are looking for

  • Tips for Creating Background Image

    I'd like to be able to use a background image on my website like this example: http://my.studiopress.com/themes/parallax/#demo-full I've found a few images, but there either to light or colorful and the white text just doesn't stand out over the imag

  • How do you change the Help title/ version number?

    Hi, When I view the primary layout, after generating it, I see a tab at the upper left, like a tab on a file folder.  It says v4.0 Online Help, but I want to update this to v4.1.  Could you tell me how to update it? Thanks, Erin

  • StageVideo in Air 2.5?

    Hi, How do I get StageVideo in Air ?

  • Sparc T5-2 servers

    Hi All, How good is the new sun sparc T5-2  in handling single threaded jobs in Oracle database. Any documents or Links will be of great help. Thanks.

  • Why does Camera App crash?

    Recently the Camera App on my iPhone 4s started to crash irregularly - in particular, when I take a picture without unlocking the screen and when I then try to look at the picture (which used to work fine before). The screen simply freezes (with a bl