Applets and DataBase Access
Hello, I want to know if it's posible data base acces from a Applet and how do it. The SQLException: No suitable Error is always in the output.The Applet code is:
import java.applet.*;
import java.awt.*;
import java.util.*;
import java.sql.*;
import java.net.*;
import java.io.*;
public class CreateCoffees extends Applet
String url = "jdbc:oracle:thin:@localhost:1521:BD";
Connection con;
String createString = "insert into COFFEES " +
"values('Pepe')";
Statement stmt;
TextArea textarea = new TextArea();
public void init()
setLayout(null);
textarea.setBounds (10,50,280,150);
textarea.setText("Empieza");
add(textarea);
try
Class.forName("oracle.jdbc.driver.OracleDriver");
} catch(java.lang.ClassNotFoundException e) {
System.err.print("ClassNotFoundException: ");
System.err.println(e.getMessage());
textarea.setText(e.getMessage());
try {
con = DriverManager.getConnection(url, "SYSTEM", "manager");
stmt = con.createStatement();
stmt.execute(createString);
stmt.close();
con.close();
} catch(SQLException ex) {
System.err.println("SQLException: " + ex.getMessage());
textarea.setText(ex.getMessage());
}
A no suitable driver error means that either your connection string is incorrect or you are not loading the driver (or failing to load it and ignoring the exception.)
Presumably you have already dealt with the problem of delivering the oracle zip file with your applet?
And you are not getting the not found exception in your code?
Similar Messages
-
PJC and database access through JDBC
Hello,
I'm trying to access to the database through a PJC via JDBC.
conn = DriverManager.getConnection ("jdbc:oracle:thin:@machine:1521:XE", "user", "pwd");It works fine on a XE database, but fails on another XE one:
Oracle JInitiator: Version 1.3.1.22
java.lang.NullPointerException
at oracle.jdbc.ttc7.O3log.marshal(O3log.java:606)
at oracle.jdbc.ttc7.TTC7Protocol.logon(TTC7Protocol.java:255)
at oracle.jdbc.driver.OracleConnection.<init>(OracleConnection.java:377)
at oracle.jdbc.driver.OracleDriver.getConnectionInstance(OracleDriver.java:515)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:345)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at oracle.forms.fd.AsyncJob.connect(AsyncJob.java:68)
at oracle.forms.fd.AsyncJob.run(AsyncJob.java:121)
at java.lang.Thread.run(Unknown Source)It also fails on a remote Unix database:
java.security.AccessControlException: access denied (java.net.SocketPermission monadev resolve)
at java.security.AccessControlContext.checkPermission(Unknown Source)
...so I edit the java.policy file of the Jinitiator directory:
permission java.net.SocketPermission "machine:port-", "accept,connect,listen,resolve"; and then get the same execption:
java.lang.NullPointerException
at oracle.jdbc.ttc7.O3log.marshal(O3log.java:606)
at oracle.jdbc.ttc7.TTC7Protocol.logon(TTC7Protocol.java:255)
...Finally, it work on only one machine and only a local database.
I'm probably missing something somewhere.
Is anyone could give me some light on this ?
Thanks in advance,
FrancoisI'm just learning to work with PJC's, so I'm unsure whether I can help, but here goes. I found the following archived on Google Groups (http://groups.google.com):
Hi. The basic applet security model is that it can only make connections
back to the machine from which it was downloaded. If you want to do
JDBC from an applet to a DBMS not on the applet-server machine,
you need a type-3 JDBC driver. A type-3 JDBC driver has an all-Java
client driver piece which an applet can download and use. This driver
piece connects to a proxy piece which is running on the webserver
machine. This proxy piece then connects to any DBMS anywhere on the
net, and is the middleman between the JDBC client and DBMS.
For security, management and performance reasons it's usually better to
constrain JDBC to a middle tier such as in a servlet, and use HTML to and
from the client, rather than the space and time involved in downloading a
full general query engine (a JDBC driver) to a client which typically uses
.1% of the capability or classes of the JDBC driver.
Joe Weinstein at BEA HTH,
Eric Adamson
Lansing, Michigan -
Hi;
Can i do database connectivity through applet if your answer is no then plz give me reasons why?
thanksHi,
Can i do database connectivity through applet?Applets loaded over the network are subject to various security restrictions. Although this can seem bothersome at times, it is absolutely necessary for network security, and security is one of the major advantages of using the Java programming language. An applet cannot make network connections except to the host it came from unless the browser allows it. Whether one is able to treat locally installed applets as "trusted" also depends on the security restrictions imposed by the browser. An applet cannot ordinarily read or write files on the host that is executing it, and it cannot load libraries or define native methods.
Applets can usually make network connections to the host they came from, so they can work very well on intranets.
The JDBC-ODBC Bridge driver is a somewhat special case. It can be used quite successfully for intranet access, but it requires that ODBC, the bridge, the bridge native library, and JDBC be installed on every client. With this configuration, intranet access works from Java applications and from trusted applets. However, since the bridge requires special client configuration, it is not practical to run applets on the Internet with the JDBC-ODBC Bridge driver. Note that this is a limitation of the JDBC-ODBC Bridge, not of JDBC.
With a pure Java JDBC driver, you do not need any special configuration to run applets on the Internet.
Hope this helps.
Good Luck.
Gayam.Srinivasa Reddy
Developer Technical Support
Sun Micro Systems
http://www.sun.com/developers/support -
Applets and Databases....
Hi all,
thanks in advance for any subsequent posts.
I was wondering if anyone could tell me if you use an applete to interact with a database. I have read some tutorials on this and I am confused by them. I have some classes set up to allow for connection to a mysql database, but was wanting to use an applete as apposed to a small program to start this off. At the moment I am getting a:
java.net.SocketException
MESSAGE: java.security.AccessControlException: access denied(java.net.SocketPermission 127.0.0.1:3306 connect, resolve
I am trying to connect to a Mysql database on the same system that I am trying to run the applete on.
thanks for all posts,
Mark.
Message was edited by:
Marky_boyAppologies all, found the answer is another post. I will try signing my applete...
..thanks again,
Marky Boy... -
This is my first database program using servlet. Also I use ECS to create the HTML document.
I accept data from a HTML page and display on the screen as well as writing to a TABLE (in instantDB)
Do I have to have the database connection in INIT() method ?
-------------Here's the code ---------------------------------------------------
public class work2_db extends HttpServlet {
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String dbName = "db";
String tableName = "survey";
Connection conn = null;
Statement stmt = null;
System.out.print("\nLoading JDBC driver...\n\n");
try {
// InstantDB JDBC driver
Class.forName("com.lutris.instantdb.jdbc.idbDriver");
// MS Access, use default JDBC-ODBC driver
// Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
} catch(ClassNotFoundException e) {
e.printStackTrace();
System.exit(1);
try {
System.out.print("Connecting to " + dbName + " database...\n\n");
// InstantDB
String url = "jdbc:idb:" + dbName;
// InstantDB, specify the configuration file name in URL
conn = DriverManager.getConnection(url + ".prp");
// MS Access
//conn = DriverManager.getConnection(url);
System.out.println("Connected to and created database " + dbName);
System.out.print("Accessing new " + tableName + " table...\n\n");
stmt = conn.createStatement();
} catch (SQLException se) {
se.printStackTrace();
System.exit(1);
int id=0;
//Go to the last record of the result set to get the next Survey ID
String queryString = "SELECT * FROM " + tableName ;
ResultSet rset = stmt.executeQuery(queryString);
while (rset.next()) {
id = rset.getInt("surveyid");
id++; // This is the Survey ID for this new survey.
rset.close();
int service[] = {0,0,0,0,0,0};
int level[] = {0,0,0,0,0};
Body body = new Body();
Html html = new Html()
.addElement(new Head()
.addElement(new Title("Survey Conformation")))
.addElement(body);
body.addElement(new H1("Thank you! Your Survey is accepted."));
body.addElement(request.getParameter("salutation") + " " +
request.getParameter("firstname") + " " +
request.getParameter("lastname"))
.addElement(new BR());
body.addElement(request.getParameter("company"))
.addElement(new BR());
body.addElement(request.getParameter("street"))
.addElement(new BR());
body.addElement(request.getParameter("city") + " " +
request.getParameter("state") + " " +
request.getParameter("postal"))
.addElement(new BR());
body.addElement(request.getParameter("country"))
.addElement(new BR());
body.addElement("Email: " + request.getParameter("email"))
.addElement(new BR())
.addElement(new BR());
body.addElement("You Travelled with us to : " +
request.getParameter("destination"))
.addElement(new BR());
body.addElement("You used our following Services : ");
body.addElement(new BR());
String values[] = request.getParameterValues("service");
if (values != null) {
UL list = new UL();
for (int i = 0; i < values.length; i++) {
list.addElement(new LI(values));
// setup category 1 feedback
if (values[i] != null)
service[i] = 1;
body.addElement(list);
body.addElement(new BR());
body.addElement("Your satisfaction level : ");
body.addElement(request.getParameter("level") + " " +
request.getParameter("good") + " " +
request.getParameter("better") + " " +
request.getParameter("best") + " " +
request.getParameter("very poor quality") + " " +
request.getParameter("none"))
.addElement(new BR());
body.addElement("You said we Can improve our Service as follows: " +
request.getParameter("comments"));
out.println(html.toString());
//set up category level feed back
if (request.getParameter("good") != null)
level[1] = 1;
else if (request.getParameter("better") != null)
level[2] = 1;
else if (request.getParameter("best") != null)
level[3] = 1;
else if (request.getParameter("very poor quality") != null)
level[4] = 1;
else if (request.getParameter("none") != null)
level[5] = 1;
//Now write the collected data into the database
String insertString = "INSERT intO" + tableName+
id + "," + service[1] + "," + service[2] + "," + service[3] + "," +
+ service[4] + "," + service[5] + "," + service[6] + "," +
+ level[1] + "," + level[2] + "," + level[3] + "," +
+ level[4] + "," + level[5] ;
stmt.close();
conn.close();
-------------------------Compile Errors ---------------------------------------------------------------------------------
I am getting following error for the exception handling. Can someone help me !!! PLEASEHi JDKPSSH,
Do I have to have the database connection in INIT() method ?not mandatory to have it in init() ( not INIT() ) method.
I am getting following error for the exception handling. Can someone help me !!! PLEASE Check out by putting the following statements in try block
stmt.close();
conn.close();otherwise you get a compile time error.
unreported exception java.sql.SQLException; must be caught or declared to be thrown
Thanks,
Sanath Kumar. -
hi all,
i have problem i have an application which use two database tables, our one external application store records in table A, my application continuous poll table for new entries as it get from it it do manipulation on it and store them in table B.
Someone suggest me that continuous DB table polling is not good approach rather then use JMS.
i am total novice in it do some one suggest me that is it good approach to use JMS?
if so please tell me some guide lines for programme.
Thanks & regardsBy the sounds of it we implemented a similar solution. Clustered application read X number of records from the database using pesimistic locking (select for update in oracle), put them on a local queue and updated the status flag to prevent them being re-read.
Using pesimistic locking meant that only one node in the cluster could access the database at once, which is far from ideal for performance, but does at least ensure the messages were processed only once. Another component of the clustered application read messages from the queue and performed the CPU intensive bits. It was a complete lottery whether the messages were evenly distributed between the nodes, but the law of averages suggests that they will be.
If your database records have a predicatble sequence you could do something like...
1. Select next 10 keys from an identical sequence
2. Poll for records with only those keys
3. When you've run out keys get the next 10.
Providing you have lots of records being inserted that should allow you to have multiple clients processing them without duplicates, but you would obviously have to give the full solution some serious thought e.g. What do you do if one of the clients dies effectively orphaning up to 10 messages etc. -
Something about applet and database?
applet cant write and read from outer files.
but can it read from database?if i don't modify my security policies.zhangv,
We hava a web application with an applet in it that communicates with the server over HTTP. So, you need not worry about security. We use a multi-tiered environment. That is, the middle layer uses an application server (Sybase EAServer) and the backend layer is our database (Sybase ASE 12.5). Our application server fetches the data from the database and streams XML to the applet via a servlet. You can find a wonderful example for how this works in an article on Java world, entitled:
Title: "A J2EE presentation pattern: Applets with servlets and XML"
Subtitle: "Enhance your Web interfaces with powerful XML-configured applet components"
http://www.javaworld.com/javaworld/jw-05-2002/jw-0524-j2ee.html
Hope this helps
TJJ -
Signed applet and database connetion...
Hello,
Well, I am deploying an applet application which needs to connect with a postgres database.
I put my application in my hosting then I changed my local java.policy file adding a line as
permission java.net.SocketPermission "127.0.0.1:5432", "connect,resolve";And my applet works... but I don't want that the user needs to change his policies file.
I read in somewhere in the forum if the applet is signed the user doesn't need to change anything... then I sign the applet. But it doesn't work. It looks to me that signing the applet is not enough to allows the connection.
But I don't sure.
Some body had had the same problem or am I doing some thing wrong?? Other Ideas
By the way, sorry for my bad english, I hope you can understand what I am saying.
Bye, and thanks by advance4NDR01D3 wrote:
Thanks for the answer.
That's a good test, I put some code before the DB connection to create a file:
File file = new File("tavo.txt");
boolean success = file.createNewFile();
if (success) {
javax.swing.JOptionPane.showMessageDialog(null, "YES");
// File did not exist and was created
} else {
javax.swing.JOptionPane.showMessageDialog(null, "NO");
// File already exists
}And surprisingly it creates the file. but doesn't connect to the database.
I Sign the applet by command line, like this:
keytool -genkey -alias signFiles -keystore compstore -keypass pass -dname "cn=salazar" -storepass pass
jarsigner -keystore compstore -storepass pass -keypass pass -signedjar Sproceso.jar proceso.jar signFiles
baftos wrote:Or at least one of the classes that are on the stack when you cpnnect to the database does not come from > the signed jar.Out of the Jar are the JDBC files(postgres.jar), it could be the problem??Your JAR is signed OK and this is good.
DB connections are not prohibited as such.
What is prohibited are Socket connections, which DB connections use internally.
Therefore, if any of the classes on the stack, when the Socket connection occurs
is not from your jar, it will fail. Therefore, the 3rd party files must be all in your jar.
Technically, this is easy: explode their jar and create your jar in such a way as to contain
all the files from their jar as well. Do it just as an experiment. If it works, read well
their licensing terms, which may forbid this. If they forbid it or if in doubt, contact them. -
10.1.3.2 and Database access
In version 5.x, you could bring data into MS Word directly from the database. Is this still an option in 10.1.3.? If not, what is the recommended approach. Do I login into the web tool, build the report and then export the xml?
Thanks.Hi
A decision was taken to remove that functionality, a new desktop tool to build reports is not far off ... I know, I know but what about now !
with 10.1.3.2 you can build the extract portion of the report in your browser, then using the BI Publisher > Login on the new Word plugin you can log in to the server, find your report, create a new template, test it and then upload it back to the server from word avoiding the web interface entirely.
This should be in the help for th new builder?
Tim -
Jsf and database access running in tomcat5
hi all
I have my JSF application saved on the "webapps/buydirect" directory in the tomcat container.
I'm trying to call my first page(index.jsp) but no responce.
is there any setting to be done before running the application? and which path do I have to use?.
please halp
thank youpost your faces config file and your web.xml file.
-
Newbie Database Access Question
I am familiar with SQL and database access from web programming, but have never done these things from within a Java application. My google searching has been fruitless thus far, so I'd appreciate any references to beginner's guides about how to query databases from a Java app and manipulate the resulting recordsets. Anything on Access db's would be ideal.
TIA,
JohnThanks for the reference. I have a question about this section of the tutorial:
http://java.sun.com/docs/books/tutorial/jdbc/basics/connecting.html
Under the section "Loading the Drivers" is the following paragraph:
Loading the driver or drivers you want to use is very simple and involves just one line of code. If, for example, you want to use the JDBC-ODBC Bridge driver, the following code will load it:
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Your driver documentation will give you the class name to use. For instance, if the class name is jdbc.DriverXYZ , you would load the driver with the following line of code:
Class.forName("jdbc.DriverXYZ");My question is: How do I decide which driver I need for connecting to an Access db on a Win XP machine? Is there perhaps another reference which answers these kinds of questions?
Thanks again,
John -
I want to connect an applet with an access database
I want to connect an applet with an access(*.mdb) database, how I do?
I now the jdbc odbc bridge but how work it?
Please Help me!!!!!!!!!!If you want access database please install IDSSERVER and import j102.sql.*;
Example:
import java.awt.*;
import java.io.*;
import j102.sql.*;
public class AccessMdb extends Applets {
Connection con;
ResultSet rs;
Statement stmt;
IDSDriver drv;
String _url ="jdbc:ids://localhost:your port /conn?dsn="your database"";
// make connection to database
drv = new j102.sql.IDSDriver();
try{
con = drv.connect(_url,null);
stmt = con.createStatement();
// query database
stmt.executeQuery("your SQL statement");
}catch(Exception ex){
System.out.println(ex.getMessage());
Good luck. -
Applets and accessing files confusion
Hi
I am confused about applets and their abilty to access files.
I know that applets cannot access files on a users hard drive until given pemission but if i design an applet that needs access to files on the server where it is running will it be able to read and write those files in the same location as the applet without the need to set permissions?
Any feedback would be great
NeilThe applet is very much able to read files from the server. This is easiest done by creating a URL and opening a stream to it:
URL url = new URL(getCodeBase(), "file.dat");
InputStream in = url.openStream();
// read from the stream...
in.close();
Saving files to the server is also possible without setting permissions but it's a bit harder. In short, you need some sort of server that accepts a connection and saves what you send it to disk. The server can be eg. a servlet, a database or a FTP server. -
Iv 10 Tables consisting of atleast 10 fields each in a single Database. Bt, Im only able to connect 1 table at a time to a form using an ADO Control. Im able to add data from table 'student' to text-boxes in my form. Bt, hw can I add data from field(0) of
Table 'Student' to Textbox1 and data from field(0) of Table 'Marks' to Textbox2 using VB6??
This is the current sample coding iv got to connect a single table to a form:
Global con As New ADODB.Connection
Global rs As New ADODB.Recordset
Public Function Connect()
If con.State = 1 Then con.Close
con.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + App.Path + "\bca.mdb;Persist Security Info=False"
End Function
Private Sub Add_Click()
If rs.State = 1 Then rs.Close
rs.Open "select * from student", con, adOpenDynamic, adLockOptimistic
rs.AddNew
rs.Fields(0) = (Text1.Text)
rs.Fields(1) = (Text2.Text)
rs.Fields(2) = (Text13.Text)
rs.Fields(3) = (Text4.Text)
rs.Fields(4) = (Text5.Text)
rs.Fields(5) = (Text6.Text)
rs.Fields(6) = (Text7.Text)
rs.Fields(7) = (Text8.Text)
rs.Fields(8) = (Text9.Text)
rs.Fields(9) = (Text10.Text)
rs.Fields(10) = (Text11.Text)
rs.Update
MsgBox " Record Added"
End Sub
What can I do to add fields from 2 different tables to different text boxes within the same form using a single ado control using vb6 and MS Access 2007??Hi,
Since VB6 product is not supported in this forum, you may go to these forums for support:
#Where to post your VB 6 questions
http://social.msdn.microsoft.com/Forums/en-US/6a0719fe-14af-47f7-9f51-a8ea2b9c8d6b/where-to-post-your-vb-6-questions
Thank you for your understanding.
Best regards,
Franklin
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click
HERE to participate the survey. -
How to handle and manage a multi Database access in runtime with LCDS?
Hello there
I got several customer working with the same application and I wonder how, with LCDS, to manage in a runtime a multi dataBase access; without creating a configuration "mxl" file in
the folder catalina for each database.
Indeed, each customer have their own dataBase, and so far, I did not find out how to avoid creating a config xml file in catalina for every single database; which force me to create as well for each customer a folder application, since the name of the config file in catalina require a folder application to be ran under tomcat....
Thus, my question is :
Is there anyway to create only one configuration mxl file in catalina (in the server side) and then from the client side (application) let the user select its environment (meaning its database) to run the application.... this technic can be also used for multi database environment such as : Dev / Test / Prod environment (or database) where the same application can access to.
Please if any one have an idea or already delt with; just let me know, because I'm entering in a bootle neck and the situation is getting serioulsy critical....
RegardsHello Ulrich,
with compact and repair I mean the MSAccess function "Compact and Repair".
Please follow the link below for more details:
http://office.microsoft.com/en-us/access-help/compact-and-repair-an-access-file-HP005187449.aspx
Normally you can execute this function directly in Access or with the Windows ODBC Data Sources Administrator => "Control Panel" => "Administrative Tools" => "Data Sources (ODBC)"...
I want to execute this function via cvi code and not by hand ;-).
Thank you for your support.
Frank
Maybe you are looking for
-
Wireless Network seems to be separate from wired.
I have a new WRT54G-TM router. I have two desktops connected to two of the Lan ports and various wireless devices,including a laptop, Nintendo Wii, VOIP phone, and a Tivo. Everything works as far as being able to connect to the internet. The problem
-
Itunes media on external hard drive
I have followed all Apple instructions to put all of my media on an external ( F:/ ) drive. This worked fine for a month, then profiles got mixed up and someone loaded new tunes straight into the "old" media location when the F:/ drive was not hooked
-
I am in the process of trying to transfer my iTunes library from one computer to another. Some of the music/film info has been edited (by me) in my library (using get info). When put onto new computer (following apple's instructions- using an externa
-
Pyament terms Authorizations in AP
Hello Experts, Payment terms Authorizations in AP invoice >> while creating AP invoice when we go to Accounting Tab and change the Payment terms, it says "You are not permitted to perform thi action". Although, user has got "Payment Terms" Full Autho
-
ICloud won't accept password on iPhone, then freezes...
Howdy When I try to access my iCloud account from my iPhone 4 it will not accept my password, and then freezes the phone. I have to reboot it to get it working again. Any thoughts will be appreciated. Thanks rlmslo