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 > Database Server Software > DB2 > ABOUT DB2 Query

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-23-10, 23:57
guruk2k5 guruk2k5 is offline
Registered User
 
Join Date: Mar 2010
Posts: 4
Question ABOUT DB2 Query

Hi,
I am new to DB2. and i have a problem with query execution from JSP.


feed.jsp

<&#37;@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" errorPage="" %>
<!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>Untitled Document</title>
</head>

<body>
<form action="check_feedback.jsp" method="post">
<table width="475" border="1">
<tr>
<td width="219">NAME:</td>
<td width="240"><input type="text" name="name1"></td>
</tr>
<tr>
<td>AGE:</td>
<td><input type="text" name="age1"></td>
</tr>
<tr>
<td>RNO:</td>
<td><input type="text" name="rno1"></td>
</tr>
<tr>
<td colspan="2"><form name="form1" method="post" action="">
<div align="center">
<input type="submit" name="Submit" value="Submit">
</div>
</form></td>
</tr>
</table>
</form>

</body>
</html>

check_feedback.jsp

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<html>
<head>
<link rel="stylesheet"
href="${pageContext.request.contextPath}/theme/Master.css"
type="text/css">
<title>check_feedback</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta name="GENERATOR" content="Rational Application Developer">
</head>
<body>
<% String temp1=(String) request.getParameter("name1");
String temp2=(String) request.getParameter("age1");
String temp3=(String) request.getParameter("rno1");

try {
// create data source
com.ibm.db2.jcc.DB2SimpleDataSource ds =
new com.ibm.db2.jcc.DB2SimpleDataSource();

// set connection properties
ds.setServerName("localhost");
ds.setPortNumber(50000);
ds.setDatabaseName("example1");
ds.setDriverType(4);

// get connection
java.sql.Connection con = ds.getConnection("gururaj", "sdmcet");


java.sql.Statement stmt = con.createStatement();
java.sql.ResultSet rs = null;
%><table><tr><td>
<%out.println(temp1+"\n");%>
</td>
</tr>
<tr>
<td>
<%out.println(temp2+"\n");%>
</td>
</tr>
<tr>
<td>
<%out.println(temp3+"\n");%>
</td>
</tr>
</table>
<%
String query="INSERT INTO gururaj.SAMPLE ('NAME',AGE,RNO) VALUES ('"+temp1+"',"+temp2+","+temp3+")";
stmt.executeUpdate(query);

%>


<jsp:forward page="success.jsp"></jsp:forward>
<%
rs.close();
stmt.close();
con.close();
}
catch(Exception e)
{
out.println("Error "+e.getMessage());

%>

<h1>error</h1>
<%
}

%>

</body>
</html>


i am getting this error

Error DB2 SQL error: SQLCODE: -204, SQLSTATE: 42704, SQLERRMC: GURURAJ.SAMPLE

Plz help me my mail id is guruk2k5@in.com

Last edited by guruk2k5; 03-24-10 at 00:01.
Reply With Quote
  #2 (permalink)  
Old 03-24-10, 07:24
sathyaram_s sathyaram_s is offline
Super Moderator
 
Join Date: Aug 2001
Location: UK
Posts: 4,534
The table does not exist
__________________
Visit the new-look IDUG Website , register to gain access to the excellent content.
Reply With Quote
  #3 (permalink)  
Old 03-24-10, 08:35
muffaddalDBA muffaddalDBA is offline
Registered User
 
Join Date: Mar 2010
Location: uk
Posts: 4
if table exists then check table previledge if its high level
qualifier for - ds.getConnection("gururaj", "sdmcet");
Reply With Quote
  #4 (permalink)  
Old 03-27-10, 06:10
guruk2k5 guruk2k5 is offline
Registered User
 
Join Date: Mar 2010
Posts: 4
Question Table exist

Quote:
Originally Posted by sathyaram_s View Post
The table does not exist
Sir,
The Table exists and i am able to execute query in DB2. but only through JSP i am not getting. the only problem with Recordset object i guess.
Thanks,
Reply With Quote
  #5 (permalink)  
Old 03-27-10, 06:15
guruk2k5 guruk2k5 is offline
Registered User
 
Join Date: Mar 2010
Posts: 4
Red face as per ur suggestion.

Quote:
Originally Posted by muffaddalDBA View Post
if table exists then check table previledge if its high level
qualifier for - ds.getConnection("gururaj", "sdmcet");

i am sending these both files with little bit changes
as per ur suggestion.
One more query, how to check the privilages of table. Plz guide me. Thank you.

feed.jsp
<%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" errorPage="" %>
<!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>Untitled Document</title>
</head>

<body>
<form action="check_feedback.jsp" method="post">
<table width="475" border="1">
<tr>
<td width="219">FNAME:</td>
<td width="240"><input type="text" name="name1"></td>
</tr>
<tr>
<td>MNAME:</td>
<td><input type="text" name="age1"></td>
</tr>
<tr>
<td>LNAME:</td>
<td><input type="text" name="rno1"></td>
</tr>
<tr>
<td colspan="2">
<div align="center">
<input type="submit" name="Submit" value="Submit">
</div>
</td>
</tr>
</table>
</form>

</body>
</html>



check_feedback.jsp


<%@page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<html>
<head>

<title>check_feedback</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta name="GENERATOR" content="Rational Application Developer">
</head>
<body>
<% String temp1=(String) request.getParameter("name1");
String temp2=(String) request.getParameter("age1");
String temp3=(String) request.getParameter("rno1");
int ch=0;

try {
// create data source
com.ibm.db2.jcc.DB2SimpleDataSource ds =
new com.ibm.db2.jcc.DB2SimpleDataSource();

// set connection properties
ds.setServerName("localhost");
ds.setPortNumber(50000);
ds.setDatabaseName("EXAMPLE1");
ds.setDriverType(4);

//String u="jdbc:db2://localhost:50000/EXAMPLE1";

// get connection
java.sql.Connection con=null;
java.sql.Statement stmt = null;// con.createStatement();
try{
con = ds.getConnection("gururaj","sdmcet");
stmt = con.createStatement();
out.print("OK");
// java.sql.Statement stmt = con.createStatement();
ch=1;
} catch(Exception e)
{
out.print(""+e);
out.print("r"+ch);
}
java.sql.ResultSet rs = null;
%><table><tr><td>
<%out.println(temp1+"\n");%>
</td>
</tr>
<tr>
<td>
<%out.println(temp2+"\n");%>
</td>
</tr>
<tr>
<td>
<%out.println(temp3+"\n");%>
</td>
</tr>
</table>
<%
rs.refreshRow();
rs.moveToCurrentRow();
// rs.moveToInsertRow();

//String query="INSERT INTO gururaj.SAMPLE ('NAME',AGE,RNO) VALUES ("+temp1+","+temp2+","+temp3+")";

//OR

//String query="INSERT INTO gururaj.SAMPLE VALUES('temp1','temp2','temp3')";
String query="INSERT INTO gururaj.SAMPLE VALUES ('"+temp1+"','"+temp2+"','"+temp3+"')";

stmt.executeUpdate(query);

//stmt.executeQuery(query);
%>


<jsp:forward page="success.jsp"></jsp:forward>
<%
rs.close();
stmt.close();
con.close();
}
catch(Exception e)
{
out.println("Error "+e.getMessage());

%>

<h1>error</h1>
<%
}




%>

</body>
</html>
Reply With Quote
  #6 (permalink)  
Old 03-28-10, 11:01
sathyaram_s sathyaram_s is offline
Super Moderator
 
Join Date: Aug 2001
Location: UK
Posts: 4,534
Quote:
Originally Posted by guruk2k5 View Post
Sir,
The Table exists and i am able to execute query in DB2. but only through JSP i am not getting. the only problem with Recordset object i guess.
Thanks,
check if you are connecting to the right database ...

very few messages are as concise and precise as
SQLCODE: -204, SQLSTATE: 42704, SQLERRMC: GURURAJ.SAMPLE
__________________
Visit the new-look IDUG Website , register to gain access to the excellent content.
Reply With Quote
  #7 (permalink)  
Old 03-28-10, 11:38
DB2Plus DB2Plus is offline
Registered User
 
Join Date: Jul 2009
Posts: 150
Lightbulb

Quote:
Originally Posted by guruk2k5 View Post
Hi,
I am new to DB2. and i have a problem with query execution from JSP.

// get connection
java.sql.Connection con = ds.getConnection("gururaj", "sdmcet");
String query="INSERT INTO gururaj.SAMPLE ('NAME',AGE,RNO) VALUES ('"+temp1+"',"+temp2+","+temp3+")";
stmt.executeUpdate(query);

i am getting this error

Error DB2 SQL error: SQLCODE: -204, SQLSTATE: 42704, SQLERRMC: GURURAJ.SAMPLE

Plz help me my mail id is guruk2k5@in.com
You made connection to DATABASE but CURRENT SCHEMA could be different.

The best way:

Code:
String query="INSERT INTO SAMPLE ('NAME',AGE,RNO) VALUES ('"+temp1+"',"+temp2+","+temp3+")";
stmt.executeUpdate(query);
Kara+
Reply With Quote
  #8 (permalink)  
Old 04-02-10, 09:28
guruk2k5 guruk2k5 is offline
Registered User
 
Join Date: Mar 2010
Posts: 4
Unhappy Hello all--PLZ HELP ME.

Now i am not getting any error. But the query is not executing.

<b>feed.jsp</b>

<%@ page contentType="text/html; charset=iso-8859-1" language="java" errorPage="" %>
<!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>Untitled Document</title>
</head>

<body>
<form action="check_feedback.jsp" method="post">
<table width="475" border="1">
<tr>
<td width="219">FNAME:</td>
<td width="240"><input type="text" name="fname"></td>
</tr>
<tr>
<td>MNAME:</td>
<td><input type="text" name="mname"></td>
</tr>
<tr>
<td>LNAME:</td>
<td><input type="text" name="lname"></td>
</tr>
<tr>
<td colspan="2">
<div align="center">
<input type="submit" name="Submit" value="Submit">
</div>
</td>
</tr>
</table>
</form>

</body>
</html>


<b>check_feedback.jsp</b>

<%@page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<html>
<head>

<title>check_feedback</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta name="GENERATOR" content="Rational Application Developer">
</head>
<body>
<% String temp1=(String) request.getParameter("name1");
String temp2=(String) request.getParameter("age1");
String temp3=(String) request.getParameter("rno1");
int ch=0;

try {
// create data source
com.ibm.db2.jcc.DB2SimpleDataSource ds =
new com.ibm.db2.jcc.DB2SimpleDataSource();

// set connection properties
ds.setServerName("localhost");
ds.setPortNumber(50000);
ds.setDatabaseName("cop");
ds.setDriverType(4);

//String u="jdbc:db2://localhost:1527/EXAMPLE1";

// get connection
java.sql.Connection con=null;
java.sql.Statement stmt = null;// con.createStatement();
try{
con = ds.getConnection("gururaj","sdmcet");
stmt = con.createStatement();
out.print("STATEMENT CREATED");


// java.sql.Statement stmt = con.createStatement();
ch=1;
} catch(Exception e)
{
out.print("STATEMENT CAN'T CREATED"+e);
out.print("r"+ch);
}
java.sql.ResultSet rs = null;
%><table><tr><td>
<%out.println("FNAME");%>
</td>
<td>
<%out.println(temp1+"\n");%>
</td>
</tr>
<tr>
<td>
<%out.println("MNAME");%>
</td>
<td>
<%out.println(temp2+"\n");%>
</td>
</tr>
<tr>
<td>
<%out.println("LNAME");%>
</td>
<td>
<%out.println(temp3+"\n");%>
</td>
</tr>
</table>
<%
//rs.refreshRow();
//rs.moveToCurrentRow();
// rs.moveToInsertRow();

//String query="INSERT INTO gururaj.SAMPLE ('NAME',AGE,RNO) VALUES ("+temp1+","+temp2+","+temp3+")";

//OR('FNAME','MNAME','LNAME')('FNAME','MNAME','LNAME ')

//String query="INSERT INTO gururaj.SAMPLE VALUES('temp1','temp2','temp3')";
rs.afterLast();

// rs.moveToCurrentRow();
rs.insertRow();
String query="INSERT INTO COP.NAME VALUES ('"+temp1+"','"+temp2+"','"+temp3+"')";

stmt.executeUpdate(query);
// rs.insertRow();


%>


<jsp:forward page="success.jsp"></jsp:forward>
<%
rs.close();
stmt.close();
con.close();
}
catch(Exception e)
{
out.println("INSERT FAILED"+e.getMessage());
//out.println("INSERT FAILED"+e.detailMessage);
%>

<h1>error</h1>
<%
}




%>

</body>
</html>

INPUT


FNAME: ggg
MNAME: ggg
LNAME: ggg


OUTPUT

STATEMENT CREATED
FNAME ggg
MNAME ggg
LNAME ggg
INSERT FAILEDnull
error
Reply With Quote
Reply

Tags
db2, jsp

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On