Connecting Tech Pros Worldwide Help | Site Map

Java and access database user accounts

  #1  
Old June 15th, 2009, 02:44 PM
Newbie
 
Join Date: Jun 2008
Posts: 13
Hi All,

I have just started learning java. I have a good understanding of UML 2. What i am trying to do is to make a small user authentication applet.

I have completed all of the relevant connection requirements via administration in XP but i just need a little helping hand to nudge me along.

The following script works fine, but I need some direction as to how to modify it to become an applet and to display something other than "1".

Thanks in advance

Expand|Select|Wrap|Line Numbers
  1.  
  2. package application;
  3.  
  4. import java.sql.*;
  5. public class Test {
  6.     public static void main(String[] arguments) {
  7.         try {
  8.             Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  9.             /* the next 3 lines are Step 2 method 2 from above - you could use the direct
  10.             access method (Step 2 method 1) istead if you wanted */
  11.             String dataSourceName = "mdbTEST";
  12.             String dbURL = "jdbc:odbc:" + dataSourceName;
  13.             Connection con = DriverManager.getConnection(dbURL, "",""); 
  14.             // try and create a java.sql.Statement so we can run queries
  15.             Statement s = con.createStatement();
  16.             s.execute("create table TEST12345 ( column_name integer )"); // create a table
  17.             s.execute("insert into TEST12345 values(1)"); // insert some data into the table 
  18.             s.execute("select column_name from TEST12345"); // select the data from the table
  19.             ResultSet rs = s.getResultSet(); // get any ResultSet that came from our query
  20.             if (rs != null) // if rs == null, then there is no ResultSet to view
  21.             while ( rs.next() ) // this will step through our data row-by-row
  22.  
  23.  
  24.                 {
  25.                 /* the next line will get the first column in our current row's ResultSet 
  26.                 as a String ( getString( columnNumber) ) and output it to the screen */ 
  27.                 System.out.println("Data from column_name: " + rs.getString(1) );
  28.             }
  29.             s.execute("drop table TEST12345");
  30.             s.close(); // close the Statement to let the database know we're done with it
  31.             con.close(); // close the Connection to let the database know we're done with it
  32.         }
  33.  
  34.  
  35.             catch (Exception err) {
  36.             System.out.println("ERROR: " + err);
  37.         }
  38.     }
  39.     }
  40.  
  #2  
Old June 15th, 2009, 04:29 PM
JosAH's Avatar
Expert
 
Join Date: Mar 2007
Posts: 10,634
Provided Answers: 2

re: Java and access database user accounts


Where does your database run? An Applet (nor a JApplet) can contact a database running on the client machine without some precautions. It's a security thing.

kind regards,

Jos
Reply


Similar Threads
Thread Thread Starter Forum Replies Last Post
.Net frameword Resources ( vb.net , asp.net etc...) shamirza answers 0 January 17th, 2007 08:05 AM
DB2 connect - user id question Wonderinguy answers 4 November 12th, 2005 06:00 AM
XML Resume Help Ian DeRock answers 2 July 20th, 2005 08:46 AM
User Authentication Carl J. Hixon answers 2 July 17th, 2005 08:53 AM