Simple JDBC framework

Hi All,
do you know any simple JDBC framework to use in implementing DAO layers ?
I'm not looking for ORM framework (like hibernate) but something simpler just to avoid for instance opening connections, closing them, resultsets management in a lot of methods.
Thanks
ste

I vote with Spring JDBC Template as well. Abstacts the plumbing all the control is yours.

Similar Messages

  • Persistent Bean framework

    I am struggling with an architectural question, surrounding persistent beans. Here is the problem.
    Supposed I have two classes, Group and Person. Obviously, Group contains some number of members. Thus, Group has a private HashMap (could have been Vector, but HashMap guarantees unique entries) listing all Person members. Finally, Group has get/set methods for its list of members.
    I have a simple persistence framework, whereby a "manager" can Introspect a bean, find all its properties, then save them to a data store, commonly a JDBC store, but in this case LDAP (using JNDI).
    The problem becomes how best to represent the Person members in the Group class. I could represent them as a Vector/HashMap/array of Person, but then persisting the Group becomes difficult, since when the manager Introspects the Group and finds the list of Person objects, it does not have basic elements to persist but rather complex user-defined Person objects. I do not want to store serialized objects, which make the data specific to my application, but rather the properties, so that the data can be used by other apps.
    When my data store was an RDBMS, I simply stored IDs for the list of members, since this mapped nicely to a relational model. However, in the case of an LDAP store, the member attributes (representing the list) contain a DN rather than just the ID (which is inside the DN).
    Here is my catch-22: if I store the serialized Person objects or even just the unique IDs of the Persons, then the underlying data in the LDAP directory become unique to my app; if I somehow get it to translate to the entire DN representing the Person, then my application objects become specific to my LDAP store and not reusable in other storage contexts.
    Any ideas?

    Hi Jhon,
    Nothing like that exists for DB XML at the moment. Berkeley DB JE supports object persistence in Java using simple annotations, if that's what you need.
    John

  • Unable to load JDBC driver

    Hello All -
    I'm new to Java and I'm attempting to connect a newly created MySQL database to a simple Java application as shown here.
    import java.sql.*;
    public class SimpleJDBC {
    public static void main(String[] args) throws SQLException, ClassNotFoundException{
    // Load the JDBC driver
    Class.forName("c:/Drew/JDBCon/mysql-connector-java-5.0.6-bin.jar");
    System.out.println("Driver Loaded!!!");
    // Establish a connection
    Connection connection = DriverManager.getConnection("jdbc:mysql://root/ce_workshop");
    System.out.println("Database connected");
    // Create a statement
    //Statement statement = connection.createStatement();
    // Execute a statement
    //ResultSet resultSet = statement.executeQuery("SELECT * FROM XXX");
    // Iterate through the results
    //while (resultSet.next())
    // System.out.println(resultSet.getString(1));
    // Close the connection
    connection.close();
    1) I've setup a the following directory in Microsoft Windows:
    C:\Drew\JDBCon\
    2) I've added the mysql-connector-java-5.0.6-bin.jar file to the C:\Drew\JDBCon\ directory
    3) I've added the SimpleJDBC.java file to the C:\Drew\JDBCon\ directory
    4) I've compiled the SimpleJDBC.java file using the following:
    C:\Drew\JDBCon>javac -cp C:/Drew/JDBCon SimpleJDBC.java
    5) Then I run the file:
    C:\Drew\JDBCon>java -cp C:/Drew/JDBCon SimpleJDBC
    But get the following error:
    Exception in thread "main" java.lang.ClassNotFoundException: c:/Drew/JDBCon/mysql-connector-java-5.0.6-bin.jar
         at java.lang.Class.forName0(Native Method)
         at java.lang.Class.forName(Unknown Source)
         at SimpleJDBC.main(SimpleJDBC.java:7)
    I've tried many things, but nothing seems to work.
    Any help is greatly appreciated!
    Thanks,
    Drew

    Hi jschell,
    Just a little background...
    For the last 4-5 years, I've been using Microsoft Access and VBA to develop databases and small utilities to assist in certain jobs at the company I work for.  Due to being a small division of a large corporation, and the reluctance for upper management to modify the purchased company databases, a small group of us started simple data extracts years ago and then uploaded the data it into Microsoft Access for both analytical and reporting purposes.  As you may know, Access is very limited, and we�ve taken it far beyond the intended limit.  We deliberately do not load some data tables due to the overwhelming size (2+ million records).
    In the last 6 months, in my free time, I�ve taken the initiative to learn (or attempt to learn) both MySQL and Java (SQL is no problem for me).  I�ve bought �Introduction to Java Programming - Comprehensive Version - 5th Edition� and read a good majority of it (some parts skimmed) along with reading a MySQL book; majority of it being SQL that I already understand and have for years.
    I completed the book last week; keep in mind, not in utter detail.  I had thought that I could get started with a simple application that would connect to a simple MySQL table and then build an understanding of the Java language from there.
    I didn�t mention in my last post that I was able to get the MySQL driver to load and a connection established in Netbeans.  I figured that instead of completely relying on Netbeans for my first real application that I should get it to work through the DOS prompt.
    I realize that my understanding of Java is probably at a 3 on a scale of 1-100 right now, however that is why I�m writing to this forum.  My main goal is to get the simplest possible application running using a MySQL driver and obtain a connection.  I would greatly appreciate any help in getting this done, or a recommended website tutorial on creating a simple JDBC application.  I�ve attempted to find these, and did, but wasn�t able to find anything that I could understand.
    Also, I do understand classes and that you import, extend, or inherit them when writing programs, I just haven�t had the chance yet to practice this.
    Regards,
    Drew

  • Need help in design/framework of a project requirements

    Hi there.
    I need some input/design suggestion and/or comments regarding 2 projects that I'm undertaking currently. The project duration is 8 weeks starting now.
    Some background information of the current technology we are using right now. We are using weblogic 7.0 SP2 and our database is ms sqlserver 2000 and/or mysql. The persistance layer/framework we are using is a home grown JDBC framework. We are using only stateless session beans and our client which is a swing ui access the servers side thru webservices via a session facade. We use also Transfer objects on the client and our own DataObjects on the server side. Current consideration is that we can not upgrade to the current weblogic version at this time and can only use java 1.4 and use existing persistence framework we have. I've considered using Spring/Hibernate but it will involve major refactoring on our existing system, which we can not afford right now. But we can augment or add new framework to handle this 2 projects.
    1. The first project is a mass update/creation of orders and order items. In our system the update and creation of order and order items are complicated and perform several validations (e.g. vendor/client is valid; item are valid and have enough to on-hand, etc.) and lookups before we can create/update an order and it's order items. We estimated that process to be around 1.5 - 3.0 secs and typically we will be processing between a few hundreds to about 5000. The max ceiling we put is 10,000.
    Now the requirements are:
    a. Ensure that the process will be completed and in the event of failure (physical or network or power) and recovery to start where it failed and start processing from that point of failure.
    b. The transaction should be atomic on per order basis and not on whole process - meaning we will commit all changes for an order and start a new transaction on the next order. This will ensure that we have a complete order committed.
    c. Don't tie the client from this process and when the process is finished give a feedback to the client who invoke the process.
    2. The second project is related to the first, is that before they post the process above, the user will look at the set of data and do some editing and then post the data. So this project is on the UI side and would present the user a table/grid view of the data and since data set could be large, we want our swing ui to fetch only a set of rows/data so that it does not take so long to load all the data or run out of memory. A button or by the user scrolling on the scrollbar would fetch the next succeeding rows/data. The problem we have as stated on the first paragraph is these- we are using webservices and stateless session beans and there is no way that the server can recognized who the user is when that user request the next set of row/data set without querying the database again.
    So your input and help is very much appreciated and if you know an existing framework that would help me is most welcome.
    Have a blessed day.
    Jun Victorio

    Take the statistics of the tables and check again.
    begin
    DBMS_STATS.gather_table_stats(ownname=>'syslog',tabname=>'logs');
    end;
    Regards
    Asif Kabir

  • Help Needed : Setting JDBC Datasource in Crystal XI using Sybase 12.5??

    All,
    We are migrating our systems to the Crystal XI from Crystal 9 Reporting Servers. I need some technical assistance on the Java API ( use of the Datasources) .
    Problem: Currently in Crystal 9 we are using OLEDB datasources to connect to various Sybase 12.5 databases (which is been set programmatically at runtime). After I changed the Java code for getting the report object from the Crystal XI server instead of 9.  I stared facing the dbLogon failed exceptions.. But surprisingly it does work randomly on only one datasource for a given session (AppServer Restart).
    Need Help on Topics:
    1. Is there any different way of configuring/usage the OLEDB datasources for CrXI? or any Java API changes while setting the datasource when using OLEDB?
    2. Configuration required for using Simple JDBC connection (Sybase) instead of OLEDB? Can I get detailed help on this.
    I will prefer using JDBC for CrXI using the Sybase 12.5, but there are very less documentation for how to configure and set databases at runtime.
    Many Thanks in Adv.
    Regards - Sudhir Deshmukh | Solutions Lead

    Hi Sudhir,
    For Building up a connection for OLEDB  we need :
    In order for Crystal Reports to connect to a database through OLE DB, there are some requirements that must be met:
    u2022     The database client software must be installed on the client machine.
    u2022     The client machine must be able to connect to the server from its client software
    u2022     The client softwareu2019s working directory (example. c:\orant\bin) must be in the Windows search path
    u2022     The OLE DB provider must be installed on the local machine.
    We have the connection for crystal reports through OLEDB :
    The process by which Crystal Reports access data from an OLE DB data source consists of these five layers:
    Crystal Reports Layer
    OLE DB Translation Layer
    OLE DB Layer
    DBMS Translation (OLE DB provider) Layer
    Database Layer
    The data translation is similar to the ODBC connection model. Crystal Reports uses CRDB_ADO.DLL to communicate to the OLE DB provider, which communicates to the database. Crystal Reports can connect to any database as long as that database has an OLE DB provider.
    When creating a new report in Crystal Reports, OLE DB data sources are found in the Create New Connection folder with the OLE DB (ADO) connection.
    Regards,
    Naveen.

  • Jdbc. The Network Adapter could not establish the connection. Help Please!!

    I've found several responses over this issue, but none works for me.
    I'm trying to setup a simple jdbc connection from a simple program.
    Platform:
    Fedora Core 4 (FC4) on AMD 64 bits
    Java 1.4.2_04 (64 bits)
    ORacle 10g or Oracle 9.2.0.4 (none works);
    Tips:
    - I can't connect to a remote server, nor to a local server
    - I can connect using SQLplus
    - TNSPing works fine
    - Listener it's up
    - my connection string is jdbc:oracle:thin:user/name@host:port:sid
    - Also try jdbc:oracle:thin:user/name@//host:port/sid
    - I'v tryied with classes12.jar, odbj14.jar
    - my hostname it's ok.
    I've monitored ip traffic on remote computer. While using TNSPING I detect activity. While using jdbc, no.
    Please, any idea??

    Thanks for your reply.
    To your questions:
    - I´v tried both IP, host, and even host.domain
    - I can connect from remote workstation using toad, and from local using sqlplus.
    - I can´t connect via jdbc.
    Folowing:
    A) my sample code
    B) the stack trace
    C) the listener status (from my 9i server. Also tryied another servr with 10g)
    when I call this program, I´ve tried severl connection strings:
    jdbc:oracle:thin:user/pass@sdd51:1521:ebf
    jdbc:oracle:thin:user/pass@:sdd51.sdd.com.ar:1521:ebf
    jdbc:oracle:thin:user/pass@:10.10.10.51:1521:ebf
    also try the other sintax:
    jdbc:oracle:thin:user/pass@//sdd51:1521/ebf
    In the classpath, I´tryied:
    clasess12.jar
    ojdbc14.jar
    nls_charset12.jar
    thanks
    A)=================================================
    // Import the JDBC classes
    import java.sql.*;
    import oracle.jdbc.pool.OracleDataSource;
    import java.io.*;
    import java.util.*;
    public class test
    // The query we will execute
    static final String query = "select 'Hello JDBC: ' || sysdate from dual";
    // The connection to the database
    static Connection conn;
    // Create the User Interface
    static public void main (String args[])
    try {
    String connect_string = args[0];
         // See if we need to open the connection to the database
         if (conn == null)
    // Create a OracleDataSource instance and set URL
    OracleDataSource ods = new OracleDataSource();
    ods.setURL(connect_string);
         // Connect to the databse
         System.out.println ("Connecting to " + connect_string + "\n");
         conn = ods.getConnection ();
         System.out.println ("Connected\n");
         // Create a statement
         Statement stmt = conn.createStatement ();
         // Execute the query
         System.out.println ("Executing query " + query + "\n");
         ResultSet rset = stmt.executeQuery (query);
         // Dump the result
         while (rset.next ())
         System.out.println (rset.getString (1) + "\n");
         // We're done
         System.out.println ("done.\n");
    catch (Exception e)
    e.printStackTrace();
         // Oops
         System.out.println (e.getMessage () + "\n");
    B)=================================================
    java.sql.SQLException: Io exception: The Network Adapter could not establish the connection
         at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:114)
         at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:156)
         at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:269)
         at oracle.jdbc.driver.OracleConnection.<init>(OracleConnection.java:212)
         at oracle.jdbc.driver.OracleDriver.getConnectionInstance(OracleDriver.java:251)
         at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:224)
         at java.sql.DriverManager.getConnection(DriverManager.java:512)
         at java.sql.DriverManager.getConnection(DriverManager.java:171)
         at oracle.jdbc.pool.OracleDataSource.getConnection(OracleDataSource.java:102)
         at oracle.jdbc.pool.OracleDataSource.getConnection(OracleDataSource.java:85)
         at test.main(test.java:66)
    C)=================================================
    LSNRCTL for Linux: Version 9.2.0.1.0 - Production on 30-JAN-2006 17:39:59
    Copyright (c) 1991, 2002, Oracle Corporation. All rights reserved.
    Connecting to (ADDRESS=(PROTOCOL=tcp)(PORT=1521))
    STATUS of the LISTENER
    Alias LISTENER
    Version TNSLSNR for Linux: Version 9.2.0.1.0 - Production
    Start Date 24-JAN-2006 11:16:18
    Uptime 6 days 6 hr. 23 min. 40 sec
    Trace Level off
    Security OFF
    SNMP OFF
    Listener Log File /opt/oracle/product/9.2.0/network/log/listener.log
    Listening Endpoints Summary...
    (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=sdd51.sdd.com.ar)(PORT=1521)))
    Services Summary...
    Service "ebf" has 1 instance(s).
    Instance "ebf", status READY, has 1 handler(s) for this service...
    The command completed successfully

  • SQL Server 2000 Driver for JDBC - Error establishing sockets

    Hi there
    I am using Microsoft SQL Server 2000 Driver for JDBC to connect to SQL Sever 2000. It is just a test application to see if it would connect to the datacase successfully. But I got the following errors. I already set up the classpath and installed all SQL Server 2000 Driver for JDBC sp 3. Dont know why it still failed...can anyone help me out of this? Thanks.
    When i am using simple JDBC-ODBC bridge Driver it's working fine.
    For this Server Pack3 , i have checked every thing like--
    TCP / IP Poart is Enable.
    I am working in client machine, my MSSQLServer 2000 Placed in server Machine.
    when i am giving Telnet ServerIP 1433 it's giving following response.
    connecting to ServerIP ....... could not open connection to the host , on port 1433:connection Failed
    My Sample Code is :--
    String user="sa";
    String password="imcindia";
    Connection con1 = null;
    CallableStatement cstmt = null;
    Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
    con1=DriverManager.getConnection("jdbc:microsoft:sqlserver://ServerName:1433;DatabaseName=dmo1o2d",user,password);
    Statement st=con1.createStatement();
    st.execute("use dm0102d");
    st.execute("setuser 'dm01012'");
    cstmt = con1.prepareCall("{?=Call dms_ex_create_folder('ABC','18753','NB21','u')}");
    cstmt.execute();
    Here are Error Code :
    java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Error establishing socket.
         at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
         at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
         at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
         at com.microsoft.jdbc.sqlserver.tds.TDSConnection.<init>(Unknown Source)
         at com.microsoft.jdbc.sqlserver.SQLServerImplConnection.open(Unknown Source)
         at com.microsoft.jdbc.base.BaseConnection.getNewImplConnection(Unknown Source)
         at com.microsoft.jdbc.base.BaseConnection.open(Unknown Source)
         at com.microsoft.jdbc.base.BaseDriver.connect(Unknown Source)
         at java.sql.DriverManager.getConnection(Unknown Source)
    java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Connection refused: connect
         at java.sql.DriverManager.getConnection(Unknown Source)
         at TestConnection1.main(TestConnection1.java:24)
    one can help me to over come this problm,
    Thanks in advance.
    venkat

    hey i also have this problem i have been looking for solution for this problem for along time i tried every possible solution i tried every service pack for the SQL but it didn't connect to the port!!!
    it's a network problem ur java code is correct dont worry about it.
    finally i had to install MySQL and it's work fine now but if u insist on usning SQL u have to use the JDBC-ODBC Bridge it will work by :
    first add data source database , follow these steps
    1- go to Administrative tools
    2-Data Sources(ODBC)
    3-System DNS tab and add then choose SQL SERVER the last option then finish
    4-write the name; Note: this name is the one that u will write in ur URL for example if u write Hello the URL will be "jdbc:odbc:Hello"
    5- choose the server, its recommended to write "." or (local)
    6-change the database to its an important step to choose the database that u want to use, choose northwind if u want to use it
    finish
    second
    adding this code:
    import java.sql.*;
    class JdbcTest1 { 
    public static void main (String[] args) { 
    try { 
    // Step 1: Load the JDBC driver.
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    // Step 2: Establish the connection to the database.
    String url = "jdbc:odbc:Hello";
    Connection conn = DriverManager.getConnection(url,"user1","password");
    } catch (Exception e) { 
    System.err.println("Got an exception! ");
    System.err.println(e.getMessage());
    it will work without any problems

  • Very strange Access / JDBC problems

    Hi there,
    I am running a simple jdbc program which uses MS Access 2000.
    I am getting this really strange problem. My program does not update the table and throws no exception - when I run the same program through a remote debugger - it does update the table.
    Is there any known JDBC / Access problems?
    Many Thanks

    There's no such thing as 91% Java Developer - you're either certified or you're not. Sounds like you're 0%.
    If you're really that knowledgable about Java, go back and re-read your question. Ask yourself: "Could the problem be me? Is there anything I'm doing wrong with JDBC that could have caused this?" I think it's likely. I'm telling you that I can insert, delete, and update with Access via the JDBC-ODBC bridge and make them stick. If you can't, I'd say you've done something wrong.
    Access 2000, Win 2000/XP Professional, JDK 1.4.1 are what I'm using. If those are the versions you've got, then there's no bug. It's you.
    JDBC-ODBC bridge isn't a M$ product, either. You can find bugs on it in the database.
    I don't see how anybody here has been that abusive of you. (I've read far worse.) It sounds like your ego would prefer that the problem lie elsewhere than inside your code.
    Do you want to make your code work or not? If so, stop calling us idiots and post something so we can take a look.
    I'd get a new ID. If you don't want to be treated as a newbie, don't use a newbie name. - MOD

  • NullpointerException while returning XML bean from JDBC Control

    Hi,
    I have a simple jdbc control method which returns multiple rows of a table. i am trying to get the data in XML bean format and followed the instruction provided in the help documentation.
    None of the columns in table has null values.
    The exception I am getting is
    Exception in getActiveAlertList
    java.lang.NullPointerException
    at org.apache.beehive.controls.system.jdbc.RowToXmlObjectMapper.mapRowToReturnType(RowToXmlObjectMapper.java:102)
    at org.apache.beehive.controls.system.jdbc.DefaultXmlObjectResultSetMapper.mapToResultType(DefaultXmlObjectResultSetMapper.java:59)
    at org.apache.beehive.controls.system.jdbc.JdbcControlImpl.execPreparedStatement(JdbcControlImpl.java:365)
    at org.apache.beehive.controls.system.jdbc.JdbcControlImpl.invoke(JdbcControlImpl.java:223)
    Any help is appreciated.

    Hi!
    I?m facing this same problem.
    Have you found a solution?
    I also tried to migrate an WL 8 application, that works with a DB Control, but got the error anyway.
    If you, or someone else, found the solution, please share. I?d appreciate.
    Thanks.
    Gustavo

  • Not comitting database after the update query in jdbc

    Hi all,
    This is the first time I am posting this. I have query excuting on racle DB. This is update query. after executing the i have called commint using con.commit(). But still it is not showing the modifications in oracle db.
    What could be went wrong? Any sugestion, please let me know. I think it is simple jdbc program. So i don't think i need to post the code. Application running in Unix machine.
    Regards & thanks,
    Nirmala Vijaya Sekhar Varre

    VijayTechM wrote:
    Connection con = null;
    Class.forName("oracle.jdbc.driver.OracleDriver");          
    hi all,
    // following is the code
    con = DriverManager.getConnection("jdbc:oracle:thin:@10.129.239.43:1529:PBILLING","BILLING","BILLING");
    boolean test = con.getAutoCommit(); //here I am getting 'true'
    String invoice_header_query = "update invoice_header set file_traffico = '" + zipFileName + "' where bill_ref_no = '" + billRefNo_ + "' and bill_ref_resets = '" + billRefResets_ + "' and arbor_instance_id = '" + arborID_ + "'";
    System.out.println("invoice_header_query---->"+invoice_header_query);
    smt = con.createStatement();
    int x = stmt.executeUpdate(query); // Here x = 1 printing so it is updating the one record
    // con.commit(); // Even I have tried call this method. But this will be useful when you are using the Transactioon.
    Could you please tell me what went write. I am using ojdbc14.jar.
    regards,
    VijayPost with code tags and where is your claimed exception handling?

  • What is wrong with my tiny jdbc program? Help!!!

    Hi,
    Would anyone diagnose the problem of my simple jdbc program?
    The situation is :
    a) local machine oracle thin driver connection; "lsnrctl" is running.
    b) I can query the statement "select id from gameUser" from SQLPLUS logged in as "scott", with desirable result.
    c) There are two code lines commented out in the code, if I uncomment them and instead comment out their counterparts and run the program, the "rset" would contain the result I want. But if I run the program unchanged, the output is only "hi".
    d) If I change the query statement to a wrong column name or a wrong table name, there would be a sql exception. So I surmise that the connection with the database is successful. But how come there is no query result???
    The follow is my coding.
    import java.sql.*;
    class dbAccess {
    public static void main (String args []) throws SQLException
    DriverManager.registerDriver (new oracle.jdbc.driver.OracleDriver());
    try{
    Connection conn = DriverManager.getConnection
    ("jdbc:oracle:thin:orcl", "scott", "tiger");
    // ("jdbc:oracle:thin:orcl", "system", "manager");
    Statement stmt = conn.createStatement();
    ResultSet rset = stmt.executeQuery("select ID from scott.gameUser");
    // ResultSet rset = stmt.executeQuery("select BANNER from SYS.V_$VERSION");
    while (rset.next())
    System.out.println (rset.getString(1)); stmt.close();
    System.out.println("hi");
    }catch (Exception e)
    System.out.println(e.toString());
    Thanks for help!

    "local machine oracle thin driver connection;" means that my jdbc application uses Oracle thin driver to connect to a Oracle database. The database and the application are both on the same local machine.
    "lsnrctl" is the command line program running to accept incomming request to connect to the database, it listens on the default 1521 port.
    I inserted two rows into the table and I could query these two rows in SQLPLUS.
    And I tried "select ID from gameUser", "select id from scott.gameUser" and various combination, it just won't retrieve the rows I inserted in the table.

  • Why my JDBC UPdate hangs up??

    Hi, Sir::
    I use following simple JDBC Update program to update my table TEST,
    See following code:
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.SQLException;
    import java.sql.Statement;
    // create table test(Test_ID number, Test_Val varchar(30));
    public class Update {
      public static void main(String args[]) {
        Connection con = null;
        if (args.length != 2) {
          System.out.println("Syntax: <java UpdateApp [number] [string]>");
          return;
        try {
          String driver = "oracle.jdbc.driver.OracleDriver";
          Class.forName(driver).newInstance();
          String url = "jdbc:oracle:thin:@localhost:1521:usa";
          con = DriverManager.getConnection(url, "scott", "tiger");
          Statement s = con.createStatement();
          String test_id = args[0];
          String test_val = args[1];
          int update_count = s.executeUpdate("INSERT INTO test (test_id, test_val) "
                  + "VALUES(" + test_id + ", '" + test_val + "')");
          s.executeUpdate("UPDATE test SET TEST_VAL= 'John Alan' WHERE TEST_ID=1");
          System.out.println(update_count + " rows inserted.");
          s.close();
        } catch (Exception e) {
          e.printStackTrace();
        } finally {
          if (con != null) {
            try {
              con.close();
            } catch (SQLException e) {
              e.printStackTrace();
               When I run with command:
    C:\temp\javaCode>java Update 2 MyTest
    It hangs here and did not process, If I remove the statement:
    s.executeUpdate("UPDATE test SET TEST_VAL= 'John Alan' WHERE TEST_ID=1");
    it works and insert 1 record into Test Table.
    What is wrong here??
    How to fix it??
    Thanks
    Sunny

    Did you try with another Statement? I would try closing the first statement and creating a new one.
          Class.forName(driver).newInstance();
          String url = "jdbc:oracle:thin:@localhost:1521:usa";
          con = DriverManager.getConnection(url, "scott", "tiger");
          Statement s = con.createStatement();
          String test_id = args[0];
          String test_val = args[1];
          int update_count = s.executeUpdate("INSERT INTO test (test_id, test_val) "
                  + "VALUES(" + test_id + ", '" + test_val + "')");
           // close it and create a new one
           s.close();
           s = con.createStatement();
          s.executeUpdate("UPDATE test SET TEST_VAL= 'John Alan' WHERE TEST_ID=1");
    Let me know if it works.

  • JDBC or FILE???

    Hi,
      We have a scenario in which an oracle in Unix needs to be interfaced with a DB2 system. Since both are database systems is it right to use JDBC adapters and communicate??
    I am a little confused on how FILE adapters would be used...
    -Krishnan

    Hi Krishnan,
    You could use FILE adapters but then you would need to write some kind of data dump routine in the source database, load it in XI (do do data transformations) and then write a data import routine in the target database.  If no data transformations are needed, then you would probbably not even need XI.
    The better approcach would be a simple JDBC interface using XI.  For example if the UNIX Oracle is your source database, create a stored procedure or view (if you need to get data from multiple tables), create a mapping in XI, and post it DB2 again with a JDBC.

  • Why my MySQL JDBC Connect fail??

    Dear friends:
    I have following code:
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.SQLException;
    public class JdbcExample2 {
      public static void main(String args[]) {
        Connection con = null;
        try {
          Class.forName("com.mysql.jdbc.Driver").newInstance();
          //jdbc:mysql://host_name:port/dbname
    //     con = DriverManager.getConnection("jdbc:MySQL:///test","admin", "admin");
          con = DriverManager.getConnection("jdbc:MySQL://localhost:3306/test","admin", "admin");
          if(!con.isClosed())
            System.out.println("Successfully connected to " +
              "MySQL server using TCP/IP...");
        } catch(Exception e) {
          System.err.println("Exception: " + e.getMessage());
        } finally {
          try {
            if(con != null)
              con.close();
          } catch(SQLException e) {}
    }But when I run , I got following error:
    Exception: com.mysql.jdbc.Driver
    My question is:
    [1]. when I connect to MySQL Server through mySQL Client, I got
    Enter password: *****
    Welcome to the MySQL monitor. Commands end with ; or \g.
    Your MySQL connection id is 18 to server version: 4.1.21-community-nt
    Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
    mysql>
    how Can I determine MySQL Server name?? I forgot when I install, maybe MySQL is my SQL Server name
    [2]. Do I need to creat a user DSN name or System DSN name for MySQL Server?? which one is best??
    How to do it??
    [3]. How to make above simple JDBC program runnable??
    Thanks
    sunny
    Message was edited by:
    sunnymanman

    Thanks, see new errors:
    C:\Project\java>java Jdbc11
    Copyright 2004, R.G.Baldwin
    java.sql.SQLException: Access denied for user 'admin'@'localhost' (using password: YES)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:946)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2941)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:868)
    at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:3340)
    at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1238)
    at com.mysql.jdbc.Connection.createNewIO(Connection.java:2743)
    at com.mysql.jdbc.Connection.<init>(Connection.java:1553)
    at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:266)
    at java.sql.DriverManager.getConnection(DriverManager.java:512)
    at java.sql.DriverManager.getConnection(DriverManager.java:171)
    at Jdbc11.main(Jdbc11.java:23)
    C:\Project\java>
    any idea??
    here Jdbc11.java:23 is:
    Connection con = DriverManager.getConnection(
    url,"admin", "YES");
    my userID/Password = admin/admin;
    sunny
    Message was edited by:
    sunnymanman

  • JDBC Connection taking way too long

    Hi,
    I have an odd problem which has just started to happen. I am creating a very simple JDBC connection to the MS SQL Server database using the Microsoft JDBC driver. This has always worked for me in the past and has never caused any problems. Now, however, creating a connection to my database is taking about 20 seconds! This is usually a sub-second operation. I have tried to narrow down the cause, but everything I have tried has failed. Here are all the things I have tried so far:
    1. Using a different JDBC driver (several, including the ODBC bridge)
    2. Create a test app which just has my connection code and run this from different machines on the network under different JDKs
    3. Re-installed by SQL Server database
    4. Connected using IP address rather than machine name (in case it was a DNS issue of some sort)
    5. Connected using different login accounts
    6. Vertified connectivity using telnet (port 1433)
    7. Verified connectivity via ODBC in an ASP page
    If I telnet to the SQL Server service I can connection without any delay. I can also connect immediately using an ODBC connection via an ASP page, so I don't think it's a problem with my database. I just seems that connectivity from Java land of woefully slow. I have never had this problem before, it's only started happening recently. The only thing that has changed recently is that I signed up for a new ADSL provider, but I can't see how this could have any bearing as all the machines are internal and connected by a 100Mbps router!
    Here's the code I am using to test...
    long current = System.currentTimeMillis();
    Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
    Connection connection = DriverManager.getConnection("jdbc:microsoft:sqlserver://<server-ip>:1433;User=<usr>;Password=<pwd>", null);
    System.out.println(System.currentTimeMillis() - current);
    connection.close();This gives me times of about 20 seconds.
    Help!

    You are right.. but the fact that:
    a) I can telnet and connect instantly
    b) The jdbc-odbc bridge connects immediately
    .. tells me that the network is ok.. at least for native functions. The only consistency I can find is that native (windows) functions connect without any issue, but pure Java functions experience problems. It may well be an issue with my network, but it seems that the issue is isolated to the Java environment (guessing here).
    I tested this theory by simply opening a socket connection from Java, but has not problems (connected immediately).
    I tried switching on the debug messages in the DriverManager (DriverManager.setLogWriter(writer))... this didn't tell me anything.
    ... The ONLY thing I can think of trying is disconnecting from my ADSL router and trying a simple cross-over cable from one machine to the other.
    Thanks for your help though.

Maybe you are looking for

  • Command Similar to "IN LIKE"

    select * from emp where deptno in like ('10%','20%') i need similar command to perform the above sql. i cannot give or comman as no of departments inside the in like clause is dynamic.. Pls Help Thanks Vinoth Edited by: suzvino on Dec 26, 2011 2:40 P

  • How to get the value a user  just enter into a table???

    hi i have a table that adds a new row when a user clicks ADD button. i was able to implement this part, now the user needs to enter some data into this row, i need this data to save into file. how can i get this data from the row?????? thank you.

  • Backup From Host or Client

    I have to VMs running Windows Server 2012 R2. Should I configure the backup from the host, i.e. the host does the backup? Or should I configure the backup on the client, i.e. the VM back itself up? I guess the later might require an external drive fo

  • Difference using HDMI or DVI cable to plug into monitor?

    hey guys, i just noticed that the Mac Mini doesn't come with a cord to connect to my monitor. i don't have a DVI or HDMI cable so it's up to me which one i choose. i was just wondering if there's a quality difference between either one so i can decid

  • Chr(7)

    Hi, how to send a command to a CASH DRAWER for open? According from direction, it need chr(7) as command for action CASH DRAWER to open. Anybody can help me in coding? Thank You.