This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JDBC and the fly likes JDBC can i connect Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "JDBC can i connect" Watch "JDBC can i connect" New topic
Author

JDBC can i connect

Kajol Shroff
Ranch Hand

Joined: Dec 04, 2000
Posts: 160
Hi Everybody,
I am doing a project in which i have an applet running where there are some textfields and i wan to store the data from the applet in the database or in the text file format..
How do i go about it ...can some body throw light on this ..as i have to implement it sooner........
Kajol
Monty Ireland
Ranch Hand

Joined: Oct 03, 2000
Posts: 161
simple to do list:
1. politytool
2. create an odbc dsn entry to us a text file database
3. use jdbc 1.0 open the driver and insert rows...
hope this helps!
<code>
import java.sql.*; //import all the JDBC classes
public class CreateJoltData {
static String[] SQL = {
"create table JoltData ("+
"programmer varchar (32),"+
"day varchar (3),"+
"cups integer);",
"insert into JoltData values ('Gilbert', 'Mon', 1);",
"insert into JoltData values ('Wally', 'Mon', 2);",
"insert into JoltData values ('Edgar', 'Tue', 8);",
"insert into JoltData values ('Wally', 'Tue', 2);",
"insert into JoltData values ('Eugene', 'Tue', 3);",
"insert into JoltData values ('Josephine', 'Wed', 2);",
"insert into JoltData values ('Eugene', 'Thu', 3);",
"insert into JoltData values ('Gilbert', 'Thu', 1);",
"insert into JoltData values ('Clarence', 'Fri', 9);",
"insert into JoltData values ('Edgar', 'Fri', 3);",
"insert into JoltData values ('Josephine', 'Fri', 4);",
};
// connect via jdbc/odbc to a dir that contains text files
// for each tablename there will be a textfile * scheme.ini file created
public static void main(String[] args) {
String URL = "jdbcdbc:textDB";
String username = "";
String password = "";
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
} catch (Exception e) {
System.out.println("Failed to load JDBC/ODBC driver.");
return;
}
Statement stmt = null;
Connection con=null;
try {
con = DriverManager.getConnection (
URL,
username,
password);
stmt = con.createStatement();
} catch (Exception e) {
System.err.println("problems connecting to "+URL);
}
try {
// execute SQL commands to create table, insert data
for (int i=0; i<SQL.length; i++) {>
stmt.execute(SQL[i]);
}
con.close();
} catch (Exception e) {
System.err.println("problems with SQL sent to "+URL+
": "+e.getMessage());
}
}
}
</code>
------------------
Multi-Platform Database Developer ( on E.S.T. )


Multi Platform Database Developer & DBA on E.S.T.
Rebecca Pickett
Greenhorn

Joined: Aug 16, 2000
Posts: 15
Originally posted by Monty Ireland:
simple to do list:
1. politytool
2. create an odbc dsn entry to us a text file database
3. use jdbc 1.0 open the driver and insert rows...
hope this helps!

Monty,
Am I missing something -- what is "politytool"??
Also, I set up a User DNS connection and I ran your code. Once it attempts to execute the SQL, I'm getting an error which says: "Cannot modify the design of table 'JoltData'. It is in a read-only database." Any ideas? The file itself does not have any special permissions on it.
Thanks,
Rebecca

[This message has been edited by Rebecca Pickett (edited April 11, 2001).]
Monty Ireland
Ranch Hand

Joined: Oct 03, 2000
Posts: 161
1. POLICYTOOL is a java utility used to grant permissions.... security etc...

Please review the java doc and this jdbc form for politytool ussage.... search for POLICYTOOL and/or Monty
2. I just ran my code and it worked fine....
3. I think you need to run POLICYTOOLs.
4. For more information please review JDBC API TUTORIAL... 'IDBC 0-201-43328-1' contains a good applet/jdbc example if you need more information...
------------------
Multi-Platform Database Developer ( on E.S.T. )

[This message has been edited by Monty Ireland (edited April 11, 2001).]
Kajol Shroff
Ranch Hand

Joined: Dec 04, 2000
Posts: 160
Hi Monty,
Sorry to say but since i am a beginner for JDBC, if you dont mind can u please explain me the code and i tried to compile your code but it gives me error..
Waitng for your reply..Monty and thanks a lot for ur help...
Kajol
Monty Ireland
Ranch Hand

Joined: Oct 03, 2000
Posts: 161
So you are new to JDBC... welcome
Since you are new to jdbc... I think you should beg borrow and/or steal the following book:
'JDBC API Tutorial and Reference, 2nd Edition' ISBN 0-201-433-28-1 .... read chapt 2 its about 50 pages... very good tutorial...
good examples...
Before we being... What is you backround...
Mine is:
15 of software development experience...
10 yrs dev database application software..
For 3 yrs I have been teaching myself java...
Last summer i passed the SCJP2 (310-25) exam...
I develope software on MVS UNIX NT
Using DB2 ORACLE Cloudscape
With ASSEMBLER, COBOL, C, PERL, & JAVA....
Presently I have java & other tools installed on NT and win98...
jdk1.3 j2sdkee1.2.1 tomcat3.1 cloudscape3.6
My current assignment has me developing a database application using oracle pro*c pl/sql & c w/ embedded sql. It's a living...
Pls reply w/ you backround...
Feel free to send me an email directly...
I chack java rach posts 3 - 4 times a day...
my emails at home avery day or so...
Monty -- aka monty6 before proper names

------------------
Multi-Platform Database Developer ( on E.S.T. )
Kajol Shroff
Ranch Hand

Joined: Dec 04, 2000
Posts: 160
Hi Monty,
Thanks for ur prompt reply.
I went throught ur mail and its very much impressive.
Well i am a beginner and have emailed u in detail about me.
Will wait for ur reply.
Kajol
Kajol Shroff
Ranch Hand

Joined: Dec 04, 2000
Posts: 160
Hi Everybody,
Please reply to me ..
I need to implement it ..
Thanks a lot in advance..
Kajol
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: JDBC can i connect
 
Similar Threads
passing variable from one applet to another applet
create new event
jsp-applet-jsp communication
Refresh problem in applet
applet in browser