Connection to the database using JSP

Forum destinado a Linguagem JAVA! Classes, orientação a objeto, conexão com banco, chamada de procedures, etc
Post Reply
jks1903
Rank: DBA Júnior
Rank: DBA Júnior
Posts: 188
Joined: Thu, 04 Feb 2010 8:08 am

Next staff.

I am developing a págia that will be a member of the company's website.
On this page I need some data that are on our basis of the Management System.

But not Esotu able to connect with the database.

I was using Dreamweaver only, and when testing on the server no data was displayed and did not return any errors, and Quety returned records.

later, I started using NetBeans and debugga I saw that it was something related to the driver, because there I did an exception and returns this error:

Oracle.jdbc.driver.oracledriver

The problem is that only iso does not mediate much, lol.

I downloaded the driver and copied it to the Tomcat lib folder (use version 6).

Has anyone ever had any seemed like, or do you have any idea what might be the mistake?

follows the excerpt from the Code for Coenxão with the Bank:

Select all

 
        <% 
String JDBC_DRIVER = "oracle.jdbc.driver.OracleDriver"; 
String DB_URL = "jdbc:oracle:@192.168.7.1:1521:PROD"; 
String DB_USER = "website"; 
String DB_PASS = "siteweb"; 
 
Connection connection = null; 
try { 
Class.forName(JDBC_DRIVER).newInstance(); 
connection = DriverManager.getConnection(DB_URL, DB_USER, DB_PASS); 
 
out.println("Conexão realizada com sucesso."); 
 
 
} 
catch (Exception e){ 
	out.println("Erro ao acessar banco de dados!<BR>" + e.getMessage()); 
} finally { 
	out.println(" "); 
} 
%> 
victorhugomuniz
Moderador
Moderador
Posts: 1396
Joined: Fri, 01 Feb 2008 2:06 pm
Location: Rio de Janeiro - RJ
Contact:
:D

Then Filhão ...

There is a variable called classpath .. Add your jar drive to this variable q will fit ...

your page / application is not filling the class that you are sending to load .. she can not find oo jar that you downloaded .. just point the jar for your application
jks1903
Rank: DBA Júnior
Rank: DBA Júnior
Posts: 188
Joined: Thu, 04 Feb 2010 8:08 am

Dude, I did not understand very well, but let's see ...

The classpath that you speak is a Variavable of Tomcat, that?
If so, where do I locate the same?

In this variable the application directory is informed, in which I must copy the Oracle driver.


Is this the idea?

vlw.
victorhugomuniz
Moderador
Moderador
Posts: 1396
Joined: Fri, 01 Feb 2008 2:06 pm
Location: Rio de Janeiro - RJ
Contact:
:D

Does your project have a lib folder?
Do you know how to configure the classpath of your application?


The idea to make your application know where this jar contains the class that you use ("oracle.jdbc.driver.oracledriver") in this code ..

can do this from various ways ..

I advise you to put the jar inside the lib folder that is ..
.. \ webcontent \ Web-inf \ lib

and on the netbeans even you get a way to "register" the jar in the application classpath .. in the eclipse just right-click and go to
Build Path
Configure Build Path
and la locate JAR and add it
jks1903
Rank: DBA Júnior
Rank: DBA Júnior
Posts: 188
Joined: Thu, 04 Feb 2010 8:08 am

Dude, sorry for the delay, Rrs was kind of out of time.

Good, on the classpath, I never configured no, I do not even know how to do it.
I even tried to look for some tutorials but still so I could not do it.

The case is that the maximum I did were validations of form, some calculations and etc, no access to the database with JSP.

But I believe I'm close, rsrs

Would not you have an example of how to set up the classpath?

vlw.
victorhugomuniz
Moderador
Moderador
Posts: 1396
Joined: Fri, 01 Feb 2008 2:06 pm
Location: Rio de Janeiro - RJ
Contact:
:D

http://javahowto.blogspot.com/2006/06/s ... beans.html
to Configure Build ClassPath, In Eclipse Project Properties Window, Click Java Build Path In The Left Panel, And In The Right Panel Choose Libraries Tab. There are more classpath-related elements in eclipse: jars, external jars, variables, libraries, class folders, and other projects. Click add external jars (not add jars) if you want to add to jar file to classpath, and click add class folders if you want to add a directory or folder to classpath.


http://www.cs.iastate.edu/~lmiller/cs36 ... clipse.htm
jks1903
Rank: DBA Júnior
Rank: DBA Júnior
Posts: 188
Joined: Thu, 04 Feb 2010 8:08 am

Dude, I got the connection, haha ??vlw.

But now another question came up, qua may be categorized as a DBA, but I will try to take advantage of the topic.

I performed the connection with a DBA user. However by security reasons I would like to make the connection with another user, which would have only privilege to do select in some views that contain the information that will be made available.

I tried with Grant Connect to [Name_USER] but still I could not.

Would you tell me what I need to do for a "normal" user can make the connection with the database?

vlw.
victorhugomuniz
Moderador
Moderador
Posts: 1396
Joined: Fri, 01 Feb 2008 2:06 pm
Location: Rio de Janeiro - RJ
Contact:
:D

I did not understand your new doubt ..

You created a user? Did not you log in with it at the bank?

to make him access his view just turn something like ..

Select all

 
grant select on sua_view to seu_user; 
jks1903
Rank: DBA Júnior
Rank: DBA Júnior
Posts: 188
Joined: Thu, 04 Feb 2010 8:08 am

The connection test I made with a user who has DBA rights.
However, for security reasons I do not want / I can use this user.

The case is that our bank has schemas, I do not know if this interferes.

But when testing the connection to the bank with this "normal" user, they only have access to View, it does not log. I use the SQL Tools 1.5 tool, to work on the bank and in this tool I also can not log in with the user I created. But in the management system I can, because when creating a user in the system, it creates a user in the bank.

I do not understand why only users with DBA privilege get access to the database.

vlw.
victorhugomuniz
Moderador
Moderador
Posts: 1396
Joined: Fri, 01 Feb 2008 2:06 pm
Location: Rio de Janeiro - RJ
Contact:
:D

Do not make sense ..

You created the user and when attempting to log in which message is displayed?
What error is displayed?
jks1903
Rank: DBA Júnior
Rank: DBA Júnior
Posts: 188
Joined: Thu, 04 Feb 2010 8:08 am

Invalid logon message: User or incorrect password.

However, the user and password are these.

TNT that in the management system I can log in normally, only when I try to log in to this tool SQL Tools and the connection I established on the NetBeans is that the error occurs.
victorhugomuniz
Moderador
Moderador
Posts: 1396
Joined: Fri, 01 Feb 2008 2:06 pm
Location: Rio de Janeiro - RJ
Contact:
:D

But can you establish a Java connection via JDBC with this user?


SQL Tools and NetBeans of Bug Beauty .. You already checked if the host, sid ..?
jks1903
Rank: DBA Júnior
Rank: DBA Júnior
Posts: 188
Joined: Thu, 04 Feb 2010 8:08 am

Oops, sorry I did not answer, but I found the problem and there was no more forum.

The case was that I had created this user by the same ERP system, which for each system user creates a bank user as well.

However, speaking with the support DBAs I saw that when creating a user through SISTA the same has some configuration or something similar (that was what I understood) that does not allow direct connections to the database .

But at the end, creating a direct user by BD worked normally.

vlw.
Post Reply
  • Information
  • Who is online

    Users browsing this forum: No registered users and 9 guests