aspose file tools*
The moose likes JDBC and the fly likes problem in jsp and database connection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "problem in jsp and database connection" Watch "problem in jsp and database connection" New topic
Author

problem in jsp and database connection

amit taneja
Ranch Hand

Joined: Mar 14, 2003
Posts: 810
hi.. i m connectiong to database in jsp but following error is comming
i have one forum folder in root of webapps ( i.e webapps->root->forum )
and my DBconnection class is in ( root->forum->web-inf->classes)

but its giving error.. in my code i have put the thing in this way
....

DBconnection dbPool = null;
Connection con =null;
Statement st = null;
ResultSet rs = null;
dbPool= new DBconnection();
con= dbPool.connect();

try{
System.out.println(dbpool);
st = con.createStatement();
}


kindly help me y this error is comming...

latest error comming is this


C:\Tomcat 5014\work\Catalina\localhost\_\org\apache\jsp\forum\registration_jsp.java:6: '.' expected import DBconnection; ^ 1 error

[ December 01, 2004: Message edited by: amit taneja ]

[ December 01, 2004: Message edited by: amit taneja ]

[ December 02, 2004: Message edited by: Bear Bibeault ]

[ December 02, 2004: Message edited by: amit taneja ]
[ December 03, 2004: Message edited by: Bear Bibeault ]

Thanks and Regards, Amit Taneja
amit taneja
Ranch Hand

Joined: Mar 14, 2003
Posts: 810
in above the error comming is ...

"cannot resolve the symbol" pointing to DBconnection object ( created)

y this is comming...

regards,
amit
Jeffrey Hunter
Ranch Hand

Joined: Apr 16, 2004
Posts: 305
If you are going to reference DBConnectivity like you are in the JSP, you'll have to import it via the page directive.

You can Google JSP page directive for specific use.
[ November 30, 2004: Message edited by: Jeffrey Hunter ]
amit taneja
Ranch Hand

Joined: Mar 14, 2003
Posts: 810
thanx for reminding me


but now this error is comming
------------------


Generated servlet error:
[javac] Compiling 1 source file

C:\Tomcat 5014\work\Catalina\localhost\_\org\apache\jsp\forum\registration_jsp.java:6: '.' expected
import DBconnection;
^
1 error

----------------------

can u guide me

thanx
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30537
    
150

Amit,
Is DBconnection in a package? You can't just import a class name.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Santosh Maskar
Ranch Hand

Joined: Jul 02, 2003
Posts: 226
hey try to import the qulified name for DBConnection

like

import packagename.class
amit taneja
Ranch Hand

Joined: Mar 14, 2003
Posts: 810
now i m getting error....


javax.servlet.ServletException: [Microsoft][ODBC Microsoft Access Driver] Number of query values and destination fields are not the same.
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:862)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:795)


i just wanted to ask while update.... we should update each and every attribute of the table... or we can update part of the tables...
in my table there is no "not null" attribute of the column.

so can i update part of the attributes... but its not taking..
i have check all the column names match with name in insert statement..
which is

st.executeUpdate("insert into registration (login_name,password,firstname,lastname,Email,homepage,pic_add,signature,allow_admin,email_viewable,pvt_msgs,notified,topicview) values(username,password,fName,lName,email,homepage,picture,signature,AllowMassMail,EmailView,private_message,private_message_notify)");

pls help me what to do...
thanx
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30537
    
150

Amit,
The values need quotes. For example

I strongly recommend the use prepared statement to avoid these formatting issues.

You only need to update the attributes that have changed. It doesn't matter if they are nullable.
amit taneja
Ranch Hand

Joined: Mar 14, 2003
Posts: 810
thanx Jeanne v.much

now i m stucking with the problem..

error in insert sqljava.sql.SQLException: [Microsoft][ODBC Microsoft Access Dri
ver] Data type mismatch in criteria expression.


That is "type mismatch" problem... and let me tell u what i m doing...

i m fetching the radio button value ( yes/no) from request.getParameter()
and storing the value in String variable and trying to upload the variable value in attribute ( "yes/no" type in MS Acess )

should i conver to boolean or what ???

y this type mismatch error is comming... ???

pls help me

Regards,
amit
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30537
    
150

Amit,
No, you don't need to convert to boolean.

Can you post your updated query?
amit taneja
Ranch Hand

Joined: Mar 14, 2003
Posts: 810
well
thanx god ....problem is solved...
actually i don't know earlier that in oreder to upload "yes/no" data type in MS-Access we have to convert the value to 0/1 and then upload it..

Another problem I was facing that whenver zero leanth string was returning form request.getParameter() it was giving error regarding "zero length error" so i have to u put the "space" in STRING and then upload
but my question is y this ? even the column is not "not null"

any way i m able to successfully upload the query...

Other thing i would like to ask is that
I have a folder "forum" in "webapps->root:" and in forum folder i have put "web-inf->classes" and in classes i have put package "db" and class "dbconnection.class"
(don't get confuse i.e webapps->root->forum->web-inf->classes->db->dbconnection.class ) but pgoram is not taking this

when i put the db.dbconnection.class in root->web-inf->classes it run
but y ???

y that is not taking if i put in forum folder....


Regards,
amit
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30537
    
150

Amit,
JavaRanch is a community of people from all over the world, many of who are not native English speakers. While using abbreviations like "u" instead of spelling out "you" is convenient when text messaging your friends on a cell phone or in a chat room, it presents an extra challenge to those that are already struggling with English. Additionally, such shortcuts may confound automated translation tools that patrons of the Ranch may be making use of.

I would like to ask for your help in making the content of JavaRanch a little easier to read for everybody that visits here by not using such abbreviations.

The last post was a bit hard to follow. For example,
u = you
y = why

Thanks,
Jeanne
Forum Bartender
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30537
    
150

Amit,
so i have to u put the "space" in STRING and then upload. but my question is y this ? even the column is not "not null"

Maybe an Access quirk? That certainly isn't the case in db2 or Oracle.

when i put the db.dbconnection.class in root->web-inf->classes it run
but y ???

Note that web-inf should be WEB-INF. It is case sensitive on some servers. Also, WEB-INF needs to be a root directory according to the EAR/WAR packaging rules.
amit taneja
Ranch Hand

Joined: Mar 14, 2003
Posts: 810
ok , i will take care in furter while using abbrivation

but i did'nt get u what do u mean by
"WEB-INF needs to be a root directory according to the EAR/WAR packaging rules"

i have used WEB-INF ( uppper case )

can you please explain me in further details where i have to put the folder .. see in my last query i have wrote about my current directory strucutes..
so please help

Regards,
amit
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30537
    
150

Amit,
In the first example you have WEB-INF under forum and in the second, it is under root. The packaging rules state that the WEB-INF folder must be at the root of the war.

Servers will not recognize WEB-INF if it is in a subfolder.

For example,
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: problem in jsp and database connection