Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2010
    Posts
    2

    Unanswered: connect with jdbc to db2

    hello, i want to connect to my db2 with jdbc.

    PHP Code:
    package jdbcdb2;
     
     
    import java.sql.*;
    import java.sql.Connection;
    //import com.ibm.db2.jcc.*;
     
     
    public class Main
            
    {
        public static 
    void main(String[] argsthrows Exception {

          
    /*
            
           DB2DataSource datasource = new DB2DataSource();
            datasource.setServerName("localhost");
            datasource.setUser("db2user");
            datasource.setPassword("12345");
            datasource.setDriverType(4); //Type 4 pure Java JDBC Driver
            datasource.setPortNumber(50000);
            datasource.setDatabaseName("TESTDB");

            //Die Funktion getConnection() liefert ein Connection Objekt das die
            //verbindung zur DB repräsentiert.
            Connection con = datasource.getConnection();


            Statement stmt = con.createStatement();
            String query = ("SELECT * FROM TEST_TABELLE");


            ResultSet rs ;
            

            con.close();

            */
            // JDBC-Treiber laden
    try {

        
    /*
    Class.forName("com.ibm.db2.jdbc.net.DB2Driver");
    } catch (ClassNotFoundException exc) {
    System.err.println("Could not load DB2Driver:" + exc.toString());
    System.exit(1);
    }
    */

          
    Class.forName("com.ibm.db2.jcc.DB2Driver");
            } catch(
    java.lang.ClassNotFoundException e) {
                
    System.err.print("ClassNotFoundException: ");
                
    System.err.println(e.getMessage());
            }

    // Verbindung zur Datenbank herstellen

    try {
    String url "jdbc:db2://localhost:50000/TESTDB";
    Connection con null;
    con DriverManager.getConnection(url"db2user""Start123");


    Statement stmt con.createStatement();
    String query = ("SELECT * FROM 'auto'");
    ResultSet rs stmt.executeQuery(query);

    while ( 
    rs.next() )
            
    System.out.printfrs.getString(1));
                               
    //rs.getString(2), rs.getString(3) );




    rs.close();
    stmt.close();
    con.close();


    } catch (
    SQLException exc) {
    System.out.println("JDBC/SQL error: " exc.toString());
    return;



            }
        }

    but i becom an error

    PHP Code:
    run:
    JDBC/SQL errorcom.ibm.db2.jcc.am.ioDB2 SQL ErrorSQLCODE=-104SQLSTATE=42601SQLERRMC='auto';SELECT FROM ;<table_ref_list>, DRIVER=3.57.82
    BUILD SUCCESSFUL 
    (total time2 seconds
    anybody knows this error?

  2. #2
    Join Date
    Jun 2003
    Location
    Toronto, Canada
    Posts
    5,516
    Provided Answers: 1
    Your query "SELECT * FROM 'auto'" has incorrect syntax.

  3. #3
    Join Date
    Nov 2010
    Posts
    2
    thank you very much!

    String query = ("SELECT * FROM \"SYSTEM\".\"AUTO\"");

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •