Results 1 to 11 of 11
  1. #1
    Join Date
    Sep 2012
    Posts
    8

    Unanswered: Begginner trying to connect to DB2

    I'm very new at this so please be patient, i followed a tutorial online and managed to resolve some errors but i cant seem to resolve this one.

    What i am trying to do is connect to the sample database in db2 with jsp using eclipse. Here is a sample of my code

    Code:
    <%@page import="java.sql.ResultSet"%>
    <%@page import="java.sql.PreparedStatement"%>
    <%@page import="java.sql.Connection"%>
    <%@page import="java.sql.DriverManager"%>
    
    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
        pageEncoding="ISO-8859-1"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Insert title here</title>
    </head>
    <body>
    <%
    try
    {
    	Class.forName("com.ibm.db2.jcc.DB2Driver");
    	
    	Connection conn = DriverManager.getConnection("jdbc:db2://localhost:50000/sample","db2admin","200300837");
    	PreparedStatement Stmt= conn.prepareStatement("SELECT EMPLOYEE.* FROM sample.EMPLOYEE");
    	Stmt.executeQuery();
    	ResultSet rs= Stmt.getResultSet();
    	String word = null;
    	while(rs.next())
    	{ 
    		word=rs.getString(1);
    	}
    	
    	rs.close();Stmt.close();conn.close();
    	if(word != null)
    	out.println("Welcome to "+ word);
    	else
    	out.println("Please check your voter name and voter id...");
    
    	System.out.println("driver loaded sucesssssssssssssssssss");
    }
    catch(Exception e){
        System.out.println(e);
    
    	
    }
    
    
    %>
    </body>
    </html>

    and the error

    Code:
    com.ibm.db2.jcc.am.SqlSyntaxErrorException: DB2 SQL Error: SQLCODE=-204, SQLSTATE=42704, SQLERRMC=DB2ADMIN.EMPLOYEE, DRIVER=3.64.104

  2. #2
    Join Date
    Jun 2003
    Location
    Toronto, Canada
    Posts
    5,516
    Provided Answers: 1
    SQLCODE -204 means there is no object called DB2ADMIN.EMPLOYEE in your sample database.

    You could have looked this up in the manual yourself.
    ---
    "It does not work" is not a valid problem statement.

  3. #3
    Join Date
    Jan 2003
    Posts
    4,292
    Provided Answers: 5
    Code:
    SQL0204N  "<name>" is an undefined name.
    Andy

  4. #4
    Join Date
    Sep 2012
    Posts
    8
    but i checked my sample db, in db explorer and its there. what am i missing?

    i even tried

    Code:
    PreparedStatement Stmt= conn.prepareStatement("SELECT * FROM EMPLOYEE");

  5. #5
    Join Date
    Sep 2012
    Posts
    8
    sorry i ment data source explorer

  6. #6
    Join Date
    Jan 2003
    Posts
    4,292
    Provided Answers: 5
    You are trying to select with an unqualified Table name. DB2 will substitute the user for the the missing schema, in your case db2admin. What does not exist is "DB2ADMIN.EMPLOYEE".

    You need to qualify the table name.

    Andy

  7. #7
    Join Date
    Sep 2012
    Posts
    8
    Quote Originally Posted by ARWinner View Post
    Code:
    SQL0204N  "<name>" is an undefined name.
    Andy
    I really dont know which object in the code is it refering to, how do i fix this

  8. #8
    Join Date
    Sep 2012
    Posts
    8
    Quote Originally Posted by ARWinner View Post
    You are trying to select with an unqualified Table name. DB2 will substitute the user for the the missing schema, in your case db2admin. What does not exist is "DB2ADMIN.EMPLOYEE".

    You need to qualify the table name.

    Andy
    How do i do this?

  9. #9
    Join Date
    Jun 2003
    Location
    Toronto, Canada
    Posts
    5,516
    Provided Answers: 1
    Add the correct schema name.
    ---
    "It does not work" is not a valid problem statement.

  10. #10
    Join Date
    Jun 2003
    Location
    Toronto, Canada
    Posts
    5,516
    Provided Answers: 1
    ---
    "It does not work" is not a valid problem statement.

  11. #11
    Join Date
    Sep 2012
    Posts
    8
    Quote Originally Posted by n_i View Post
    Add the correct schema name.
    finally figured out the schema name thank you, for your help

Posting Permissions

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