If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > JAVA > connect with jdbc to db2

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-04-10, 05:47
blade999 blade999 is offline
Registered User
 
Join Date: Nov 2010
Posts: 2
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?
Reply With Quote
  #2 (permalink)  
Old 11-05-10, 09:01
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
Your query "SELECT * FROM 'auto'" has incorrect syntax.
Reply With Quote
  #3 (permalink)  
Old 11-05-10, 11:16
blade999 blade999 is offline
Registered User
 
Join Date: Nov 2010
Posts: 2
thank you very much!

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

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On