Sql exception from java

Hi,
When running the below query from sqlyog it works OK but when running from java I got exception.
What can cause this difference ?
The query :
create temporary table TempTable1 SELECT salaries.salary AS `salary`,salaries.emp_no AS `emp_no`,salaries.from_date AS `from_date`,MAX(salaries.salary) AS `func` FROM `salaries` WHERE salaries.to_date = '9999-01-01'
The exception:
com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException: Column 'salary' cannot be null
Thanks

Below is the code.
When run from sqlyog is works OK.
Thanks
The code :
package client;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
public class test {
     * @param args
     * @throws ClassNotFoundException
     * @throws IllegalAccessException
     * @throws InstantiationException
     * @throws SQLException
     public static void main(String[] args) throws InstantiationException,
               IllegalAccessException, ClassNotFoundException, SQLException {
          String username = "root";
          String password = "";
          Class.forName("com.mysql.jdbc.Driver").newInstance();
          java.sql.Connection connection = DriverManager.getConnection(
                    "jdbc:mysql://localhost:3306/employees-thin", username,
                    password);
          Statement statement = connection.createStatement();
          statement
                    .execute("create temporary table TempTable1 SELECT salaries.salary AS `salary`,salaries.emp_no AS `emp_no`,salaries.from_date AS `from_date`,MAX(salaries.salary) AS `func` FROM `salaries` WHERE salaries.to_date = '9999-01-01'");
Exception in thread "main" com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException: Column 'salary' cannot be null
     at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:931)

Similar Messages

  • Connect to MS Sql Server from Java Source

    Hi,
    Is there any way I could connect to ms sql server from Java source? I know I can call java source from function thats easy but what I really want is capability to connect to non-oracle(MS SQL server) from my java source and then call it from function.
    I don't know if JDBC driver for SQL server is even installed/available. Is there a way I could find it out form my IDE? I know sqlJ does compile but I have never used sqlj. help!!!
    Sinha

    You'll probably have better luck in a Java forum or a Microsoft forum.

  • Calling a PL/SQL function from java

    I would like to call a pl/sql function from java. My pl/sql function is taking arrays of records as parameters. How do i proceed? Which specific oracle packages do I have to import?
    Please send an example.
    TIA,
    Darko Guberina

    Documentation here: http://download-uk.oracle.com/docs/cd/B14117_01/java.101/b10983/datamap.htm#sthref185
    says JPublisher can publish records too.
    But when I change the example given at http://download-uk.oracle.com/docs/cd/B14117_01/java.101/b10983/datamap.htm#sthref190 as following:
    PACKAGE "COMPANY" AS
    type emp_rec is record (empno number, ename varchar2(10));
    type emp_list is varray(5) of emp_rec;
    type factory is record (
    name varchar(10),
    emps emp_list
    function get_factory(p_name varchar) return factory;
    END;
    then I see <unknown type or type not found> at sql or java files generated. Any ideas?

  • Error PLS-00306 during calling PL/SQL function from Java

    Hi all,
    I am facing a problem during call of oracle PL/SQL function from java using CallableStatement.
    I receive following error message.
    java.sql.SQLException: ORA-06550: line 1, column 13:
    PLS-00306: wrong number or types of arguments in call to 'EXPORT_HIST_ALARMS_FUNC'
    ORA-06550: line 1, column 7:
    PL/SQL: Statement ignored
    As per above error EXPORT_HIST_ALARMS_FUNC in oracle has this signature.
    CREATE OR REPLACE FUNCTION EXPORT_HIST_ALARMS_FUNC(startDateTime VARCHAR2, endDateTime VARCHAR2, meType VARCHAR2) RETURN VARCHAR2 IS
    END EXPORT_HIST_ALARMS_FUNC;
    Above function I have called following way in java.
    String sql = "begin ?:= EXPORT_HIST_ALARMS_FUNC(?, ?, ?); end;" ;
    CallableStatement cStatement = null;
    cStatement = connection.prepareCall(sql);
    cStatement.registerOutParameter(1,Types.VARCHAR);
    cStatement.setString(2,startDateTime);
    cStatement.setString(3,endDateTime);
    cStatement.setString(4,meType);
    cStatement.execute();
    msg = cStatement.getString(1);
    Actually above function requires three input parameters and one return parameter.
    During execution of above java code it throws SQLException and shows PLS-00306: wrong number or types of arguments in call to 'EXPORT_HIST_ALARMS_FUNC' error.
    I have run this function directly from oracle with three parameters and run successfully and finally it returns string.
    But I am unable to figure out why it doesn't run from above java code.
    Please help regarding this.
    Thanks.
    Regards,
    Shardul Banker

    Try this:
    String sql = "begin ?:= EXPORT_HIST_ALARMS_FUNC(?, ?, ?); end;" ;
    CallableStatement cStatement = null;
    cStatement = connection.prepareCall(sql);
    cStatement.registerOutParameter(1,Types.VARCHAR);
    cStatement.setString(1,startDateTime);
    cStatement.setString(2,endDateTime);
    cStatement.setString(3,meType);
    cStatement.execute();
    msg = cStatement.getString(1);Regards,
    Martijn Teigeler
    Edited by: mTeigeler on Oct 13, 2007 10:22 AM

  • Calling oracle SQL Loader from java program

    Hi,
    I want to insert data into oracle tables from a text files containing fixed length fields. I am using SQLLoader to achieve this. The requirement is to call the SQLLoader within the java program.
    Does anyone know how to call SQL Loader from java program?
    Thanks,
    Varsha

    Simply "exec" the sqlldr program with the parameters you need to pass to it.
    Runtime.exec (........)
    Try to pass all parameters needed including the username and password, and use the option "silent" to avoid output, and the option "log" to have a log file of the modifications that sqlldr has done to the database.

  • Calling SQL packages from java

    How do I call ORACLE sql packages from java?
    We are still using Oracle 7.3. Any sample code
    would be appreciated.

    utility.processPLSQL( connRisk,
    " Begin "
    + " hvar_sum.p_load_var_summary_data("
    + " '" + dfCall.format( priceDate ) + "', "
    + " '" + promptMonth + "',"
    + daysBack + ","
    + aliasType + ","
    + "'" + connRisk.owner + "'"
    + "); "
    + " end ; ",
    "Load VaR Summary Data",
    utility.noLogMsg ) ;
    public boolean processPLSQL(
    MyConnection conn,
    String sql,
    String dataType,
    boolean createLogMessage ) {
    double startTime = conn.log.getStartTime() ;
    try {
    CallableStatement cs = conn.theConnection.prepareCall(sql);
    cs.execute() ;
    cs.close() ;
    conn.theConnection.commit();
    if ( createLogMessage ) conn.log.logTiming( dataType, startTime ) ;
    } catch ( SQLException e ) {
    conn.log.logError( "Utility.processPLSQL; SQLException Error: " + e ) ;
    System.out.println(new java.util.Date().toString() + "; User: " + conn.user
    + "; SQL: " + sql );
    return false ;
    return true ;
    }

  • Send Datetime2 value to a SQL Procedure from Java using Hibernate

    Hi All,
    I Have a Procedure which takes a parameter of type datetime2.
    The procedure is called from Java Hibernate.
    How can I Pass datetime2 value to SQL procedure from Java?
    Thanks in advance,
    Shraddha Gore

    You may define a global empty array in some package. Then you can do:
    SQL> CREATE OR REPLACE PACKAGE pkg
    AS
       g_empty   DBMS_SQL.varchar2_table;
    END pkg;
    Package created.
    SQL> CREATE OR REPLACE PROCEDURE p (
       p_tuids   IN   DBMS_SQL.varchar2_table "DEFAULT pkg.g_empty"
    AS
    BEGIN
       NULL;
    END p;
    Procedure created.
    SQL> BEGIN
       p ();
    END;
    PL/SQL procedure successfully completed.

  • How to isolate the Sql Statement from Java Code

    Hi
    I Need to know that can we segregate the Sql Statements and convert them to Stored Procedures so as to isolate the Sql statements from Java Code.
    So i have one static web page which uses four select Statements so what i want is to create a stored procedure encapsulating these queries. So that the Java Web Developer will simply call the Stored Procedure instead of using four different SQL Statements.
    Suppose the developer has these four Statements
    Select ename,empno,sal,job from emp;
    select empno,ename,mgr from emp;
    select deptno,dname from dept;
    select emp.ename,emp.empno,emp.deptno,dept,dname fromemp,dept;
    So can i encapsulate these four Sql Statements in one Procedure and the Web developer can call the Store procedure and dont need to write the Sql Statements in his code.
    Can Anybody guide me how to write this Stored type of Store procedure.
    Thanks

    http://www.google.com/search?q=java+windows+registry
    Next time, search yourself. It might be beyond your belief, but you're really, really not the first person to wonder about this.

  • Invoking .SQL file from JAVA

    Hi All,
    Anyway of calling .SQL files from JAVA ??
    thanks in advance..

    What do you mean by calling?
    Are you talking about a stored procedure? Then yes.typo !!
    i meant invoking .SQL script only...
    No not stored procedure..i mean running or invoking a sql file containing sql statements(inserts etc)

  • CALLING a STORED SQL FUNCTION from  Java 1.1.8

    I am trying to execute a stored function in JAVA 1.1.8, from an Oracle
    8i Database. My stored function is simple, it converts an Input Number to an output TIME string. I am unsure how to code the call from Java. Are SQL STORED PROCEDURES treated the same as SQL STORED FUNCTIONS? Do you use the CallableProcdure class or something else?
    Thanks for your input.

    yep - same way. Except no return value.

  • Multiple sql statements from java

    I am executing sql statements in MaxDB 7.6.04.12 from java using jdbc.
    I want to execute multiple statements at a time, but it seems that however I separate the statements, I get
    com.sap.dbtech.jdbc.exceptions.DatabaseException: [-3014] (at 433): Invalid end of SQL statement
    I have tried separating the statements with just a semi-colon, with a semi-colon and new line, with newline-//-newline (as works with SQL Studio), but whatever I try I get this error or some other.
    Is it possible to do this? and if so how?
    Thanks
    Chris

    Hi Lars,
    Here are the relevant bits of code.
    However I'm not sure how helpful that will be - I'm using the SpringFramework for my jdbc calls, as it saves a lot of time and effort, and my calls are to Spring methods, which are wrappers round the base jdbc calls.
    I'll post it anyway, just in case you're familiar with Spring. I haven't looked at the Spring code, but my understanding is it pretty much just passes the sql to standard jdbc calls.
    I guess my next step would be to trace through the Spring code as it executes and see if anything becomes apparent. However I'm under some time pressure and was hoping to avoid that.
    My other alternative is to create non-temporary tables, and drop them explicitly when I've finished with them.
        public Set<String> getPriceUpdatedProducts() {
            final Set<String> prods = new TreeSet<String>();
            String sql;
            int updates;
            // need single connection template so subsequent statements can access temp tables:
            JdbcTemplate jtSingle = getSingleConTemplate(jdbcTemplate);
            // inDCs is a list of dist channels for an sql 'in' statement:
            String inDCs = "";
            for (String siteId: siteConfig.getAllSiteIds()) {
                if (!"".equals(inDCs)) inDCs += ",";
                inDCs += "'" + siteConfig.getSiteIdProperty(siteId, "distChanId") + "'";
            // Clear all the changed flags from the last run:
            updates = jtSingle.update("update zchangedartdc set changed = '' ");
            // Get the current data into a temp table:
            sql = "create table temp.pricechanges as " +
                  "select A304.matnr, A304.vtweg, konp.kbetr price " +
                  "  from A304 join konp " +
                  "    on A304.knumh = konp.knumh " +
                  "   and A304.mandt = konp.mandt " +
                  "   and A304.vkorg = '" + salesOrg + "' " +
                  "   and A304.vtweg in (" + inDCs + ")" +
                  "   and A304.kschl = '" + rrpCondType + "' " +
                  "   and A304.mandt = '" + sapClient + "' " +
                  "   and konp.kschl = '" + listCondType + "' " +
                  "   and char(date, internal) >= chr(A304.datab) " +
                  "   and char(date, internal) <= chr(A304.datbi) " +
                  "   and A304.kappl = 'V' ";
            jtSingle.execute(sql);
            // Get the changes into a second temp table:
            sql = "create table temp.changedarts as " +
                  "select temp.pricechanges.* " +
                  "  from temp.pricechanges, zchangedartdc " +
                  " where zchangedartdc.matnr = temp.pricechanges.matnr " +
                  "   and zchangedartdc.vtweg = temp.pricechanges.vtweg " +
                  "   and zchangedartdc.price != temp.pricechanges.price ";
            jtSingle.execute(sql);
            // save the changes, and flag them:
            sql = "update zchangedartdc " +
                  "   set (price, changed) = (select price, 'X'  " +
                  "                             from temp.changedarts " +
                  "                            where zchangedartdc.matnr = temp.changedarts.matnr " +
                  "                              and zchangedartdc.vtweg = temp.changedarts.vtweg) " +
                  " where matnr||vtweg in (select matnr||vtweg from temp.changedarts) ";
            updates = jtSingle.update(sql);
            // add the new items that weren't there last time, and flag them:
            sql = "insert into zchangedartdc " +
                  "select '" + sapClient + "', matnr, vtweg, 'X', price " +
                  "  from temp.pricechanges " +
                  " where matnr||vtweg not in (select matnr||vtweg from zchangedartdc) ";
            updates = jtSingle.update(sql);
            // now we've got all the changes flagged, we can get the list of changed products:
            jtSingle.query("select distinct matnr from zchangedartdc " +
                           " where changed = 'X' ",
                           new RowCallbackHandler() {
                               public void processRow(ResultSet rs) throws SQLException {
                                   prods.add(rs.getString("matnr"));
            // release the connection:
            destroySingleConnection(jtSingle);
            return prods;
         * Return a JdbcTemplate which will always use the same connection. Parameter jt is just
         * a convenient way to get a DataSource from which to get a Connection.
         * When the calling prodedure has finished, it MUST call
         * destroySingleConnection(jt)
         * @param jt
         * @return
        private JdbcTemplate getSingleConTemplate(JdbcTemplate jt) {
            Connection con;
            try {
                con = jt.getDataSource().getConnection();
                con.setAutoCommit(true);
            } catch (SQLException e) {
                throw new DataAccessResourceFailureException("Failed to get Connection for SingleConnectionDataSource", e);
            SingleConnectionDataSource singleDs = new SingleConnectionDataSource(con, true);
            return new JdbcTemplate(singleDs);
        private void destroySingleConnection(JdbcTemplate singleConJt) {
            try{
                ((SingleConnectionDataSource)singleConJt.getDataSource()).destroy();
            } catch (SQLException e) {
                throw new DataAccessResourceFailureException("Failed to destroy SingleConnectionDataSource", e);

  • Throwing PL/SQL Exceptions to Java

    Hi, anyone have experience with calling a PL/SQL stored procedure from Java?
    I am using the CallableStatement, but my issue is capturing error messages
    thrown by the stored procedure. In the exception block of the stored
    procedure I throw errors using the RAISE_APPLICATION_ERROR.
    Will that raise an SQLException in Java, or does the error message get set to the CallableStatement interface's Warning message (accessed through CallableStatement.getWarnings();)? Or perhaps something else? If anyone has
    some previous experience in this area, please let me know. Thanks,
    Mac

    Shravan,
    Actually, I already know that that works. In fact, you can create two OUT parameters, on with the error code and one with the message. In your exception block you should be able to assign values to each one. When you do this, don't use the RAISE_APPICATION_ERROR procedure, for it will clear your OUT parameters.
    The issue is that this does not raise a SQLException, which is what I would like to do. Since JDBC already has the facility to raise an SQLException with an unhandled error condition in a Procedure, I am wondering if RAISE_APPLICATION_ERROR allows programmers to pipe custom errors into the JDBC as SQLException objects. The reason I want to do this is because I would like my PL/SQL procedure to handle exception conditions internally, and deliver an error which is meaningful to consumer of the service provided by the PL/SQL procedure. I can accomplish this with an OUT parameter or two, but I'd prefer to send exception conditions out of the procedure as actual SQLExceptions, rather than out parameters.

  • Throwing exceptions from Java Stored Procs

    Hi,
    We'd like to be able to define our own exceptions from our Java Stored Procedures (i'm going to call them JSP's even thought that's not PC). I am aware that the manual says "When a Java stored procedure executes a SQL statement, any exception thrown is materialized to the procedure as a subclass of java.sql.SQLexception. That class has the methods getErrorCode() and getMessage(), which return the Oracle error code and message, respectively."
    Does this mean that we can't really extend the SQLException class and define our own set of methods for handling exceptions in JSP's? Is there a work around for handling exceptions in JSP's? Since exception handling is such a powerful component of Java, I figure someone has addressed the limitations of the above paragraph.
    Thanks,
    Kristi
    null

    Unfortunately, right now GCC's standard C++ runtime library is NOT threadsafe. You can find documentation supporting this on the GCC website. Since you're running a multithreaded Java/JNI application, you'll certainly hit this shortcoming.
    <p>
    Supposedly, this will all be fixed in GCC 3.0.
    <p>
    In the meantime, if you're using SPARC, the only option you have is either using SC4.2 or Forte 6 Update 2 (this particular version is VERY important for several reasons).

  • Calling SQL LOADER From Java Program

    Hi
    I need to invoke sql loader from inside a Java Class.
    Any Pointers in this regards will be really appreciated.
    Thanks
    Vishal

    You can create two different files which has sqlldr command defined....
    1. loader.sh
    2. loader.bat
    and in the depending on the OS execute one...
             String command = "";
             if(System.getProperty("os.name").equals("Windows 2000")){
                    //if os is windows 2000  then execute bat file
                     command =  <<bat file path>>
              }else{
                      command = <<shell path>>
              Runtime rt = Runtime.getRuntime();
              Process p = rt.exec(command);
              int i = p.exitValue();
             

  • Calling PL/SQL Procedures from Java

    Hello,
    I want to know, if it is possible to call PL/SQL Procedures from
    SQLJ(which uses htp.print from the Package web toolkit ).
    Though, it is possible to call normal procedures but if I want
    to call PL/SQL procedures with htp.print then I get I error.
    For example:
    #sql{Call html_test()};
    Can you give me a advice?
    Your help is much appreciated!
    M|ller

    Oracle's htp packages are develop to be work with
    mod_plsql/OAS/OWS webserver.
    If you are trying to use htp packages first need to instanciate
    some enviroment vars for htp packages, for example first you has
    to call to owa.initialize procedure, populate owa.cgi array and
    so on.
    If you need more information about how this toolkit works you
    could get the source of DB Prism at
    http://www.plenix.com/dbprism/ this open source framework
    includes backward compatibility with mod_plsql application and
    then includes settings of this values from Java code.
    Best regards, Marcelo.

Maybe you are looking for

  • Installing a JDBC-driver in the classpath in win 2000

    Hi I'm trying to make an aplication, that can access a remote DataBase, with the mm.mysql driver. I have tryed to add the path to the libery where the jar file is in the classpath (in win 2000). But I can't get it to work from a dos-promt.

  • System.Data.SqlClient.SqlException: The locale identifier (LCID) 16393 is not supported by SQL Server

    I have SQL Server 2005 Developer Edition. And my operating system is Windows Vista. I have written a procedure in C# and deployed it on SQL Server. However when i try to run it i get the following error. System.Data.SqlClient.SqlException: The locale

  • How to apply iso coated v300 in acrobat

    I'm currently using Acrobat 10.1.8. When i apply the iso coated v300 icc profile on a file, using convert colors, the ink values do not seem to be altert to a value under 300%. In my provious version this worked, what has changed?

  • Firefox crash since last update

    I have problem on Windows 7 64 bits and the latest version of FF. Since the last update to open firefox, the process remains stuck in memory, no display. Safe mode impossible Profil manager impossible Reinstall as no effect No Malware No crash log I

  • CPS on FreeBSD

    Will CPS run on Free BSD?