Swings with database

Thread Solved

Join Date: Jun 2009
Posts: 99
Reputation: akulkarni is an unknown quantity at this point 
Solved Threads: 4
akulkarni akulkarni is offline Offline
Junior Poster in Training

Swings with database

 
0
  #1
Oct 16th, 2009
I wish to create an application using swing to update data to the database. I will need three buttons add, modify and delete.
i have so far created JDBC connection with Ms acess. i have also created a textfield where i will enter data like this...
  1. import java.awt.*;
  2. import java.awt.event.*;
  3. import java.applet.*;
  4. import javax.swing.*;
  5. /*<applet code="textfield" width=300 height=200></applet>*/
  6. public class textfield extends JApplet implements ActionListener
  7. {
  8. JTextField jtf;
  9. public void init()
  10. {
  11. Container cp=getContentPane();
  12. cp.setLayout(new FlowLayout());
  13. jtf=new JTextField(15);
  14. cp.add(jtf);
  15. }
  16. public void actionPerformed(ActionEvent ae)
  17. {
  18. repaint();
  19. }
  20. public void paint(Graphics g)
  21. {
  22. g.drawString(jtf.getText(),100,80);
  23. }
  24. }

i wish to connect swing(applet) to database.Also i am not able to view text through the paint function on the applet.

my jdbc
  1. import java.sql.*;
  2. public class Test4
  3. {
  4. public static void main(String[] args)
  5. {
  6. try {
  7. Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  8.  
  9. String dataSourceName = "mdbTest1";
  10. String dbURL = "jdbc:odbc:" + dataSourceName;
  11. Connection con = DriverManager.getConnection(dbURL, "","");
  12.  
  13. Statement s = con.createStatement();
  14. s.execute("create table TEST1223 ( id integer, name VARCHAR(32) )");
  15. s.execute("insert into Test1223"+"(id,name)"+"values('1001','nikhil')");
  16. s.execute("insert into Test1223"+"(id,name)"+"values('1002','ketan')");
  17. s.close(); // close the Statement to let the database know we're done with it
  18. con.close(); // close the Connection to let the database know we're done with it
  19. }
  20. catch (Exception err) {
  21. System.out.println("ERROR: " + err);
  22. }
  23. }
  24. }

i would love if someone helps with this code(modify it) also something about "modify"button(its nature)
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 2,357
Reputation: masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of 
Solved Threads: 252
Moderator
masijade's Avatar
masijade masijade is offline Offline
Nearly a Posting Maven
 
1
  #2
Oct 16th, 2009
MS Access is file based (i.e. no remote connections, local file access needed) and Applets do not have access to the local file system. A complete redesign is in order.
Java Programmer and Sun Systems Administrator

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

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 91
Reputation: Clawsy is an unknown quantity at this point 
Solved Threads: 4
Clawsy Clawsy is offline Offline
Junior Poster in Training
 
0
  #3
Oct 16th, 2009
I need more details. I don't understand what you are actualy doing. The best method would be to make a JTable in which you can see your database table records. Then you can go further. I mean how can you modify something if you can't see what row u actualy modify? (I'm guessing)
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 53
Reputation: di2daer is an unknown quantity at this point 
Solved Threads: 12
di2daer's Avatar
di2daer di2daer is offline Offline
Junior Poster in Training
 
0
  #4
Oct 16th, 2009
I think that you can write a server/client solution to get it to work. The client connects to the server which returns the content of the database. I did something like that when I needed my applet to read from a database, but I don't remember all the details.
---------------------------
333 - halfway to hell
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 2,357
Reputation: masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of 
Solved Threads: 252
Moderator
masijade's Avatar
masijade masijade is offline Offline
Nearly a Posting Maven
 
0
  #5
Oct 16th, 2009
Originally Posted by Clawsy View Post
I need more details. I don't understand what you are actualy doing. The best method would be to make a JTable in which you can see your database table records. Then you can go further. I mean how can you modify something if you can't see what row u actualy modify? (I'm guessing)
Under normal circumstances, how is he to access an MS Access DB from an Applet? It is the pinnacle of arrogance to suggest that the clients should modify their security settings for your app.
Java Programmer and Sun Systems Administrator

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

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 2,357
Reputation: masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of 
Solved Threads: 252
Moderator
masijade's Avatar
masijade masijade is offline Offline
Nearly a Posting Maven
 
0
  #6
Oct 16th, 2009
Originally Posted by di2daer View Post
I think that you can write a server/client solution to get it to work. The client connects to the server which returns the content of the database. I did something like that when I needed my applet to read from a database, but I don't remember all the details.
An applet has no problems connecting to a DB, as long as the DB exists on the same server as the machine that served the page, and the DB is a client/server DB and not MS Access.

Of course you can build your own client/server protocol and connection to enable connection to MS Access, but why? Why pay the hefty license and software costs only to have to build your own (possibly buggy) access routines in order to be able to even use it when there are a plethora of free client/server DBs out there, and most of them are better than MS Access in the first place.
Last edited by masijade; Oct 16th, 2009 at 5:31 am.
Java Programmer and Sun Systems Administrator

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

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 2,357
Reputation: masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of 
Solved Threads: 252
Moderator
masijade's Avatar
masijade masijade is offline Offline
Nearly a Posting Maven
 
0
  #7
Oct 16th, 2009
Originally Posted by masijade View Post
MS Access is file based (i.e. no remote connections, local file access needed) and Applets do not have access to the local file system. A complete redesign is in order.

Sorry, of course a complete redesign is not in order, but you do need to change DBs.
Java Programmer and Sun Systems Administrator

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

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 99
Reputation: akulkarni is an unknown quantity at this point 
Solved Threads: 4
akulkarni akulkarni is offline Offline
Junior Poster in Training

swings and jdbc

 
0
  #8
Oct 16th, 2009
The question i have is: Create a java application which will add, modify,delete records from employee database.The database has 3 fields emp_id, empname and department location.All information accepted from GUI and stored in the database(hint:use jdbc)

so in the first part of my code i was trying to create a textfield for data entry. When i enter text in the textfield and click the add button the information should get updated in the database.We will be using MS access as the database.

In the next code i have just demonstrated what code i will be using as a response to the GUI event.

It need not be an applet but any GUI java application.dialog box, Jpane etc.(calling functions using main())
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 2,357
Reputation: masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of 
Solved Threads: 252
Moderator
masijade's Avatar
masijade masijade is offline Offline
Nearly a Posting Maven
 
0
  #9
Oct 16th, 2009
Then normal swing standalone app.

A preparedstatement, its setString method, and the textfields getText method.

That should get you started.
Java Programmer and Sun Systems Administrator

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

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 99
Reputation: akulkarni is an unknown quantity at this point 
Solved Threads: 4
akulkarni akulkarni is offline Offline
Junior Poster in Training

swings with database

 
-1
  #10
Oct 16th, 2009
Can u please get me clear with how i should configure events like the button clicked and also how do i write two classes ..i mean one for swing and other for jdbc.May be a bad question for my level ...what does actionPerformed do and also addActionListener in general and in this case
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC