NEED HELP!!!

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Apr 2008
Posts: 36
Reputation: didi00 is an unknown quantity at this point 
Solved Threads: 0
didi00 didi00 is offline Offline
Light Poster

NEED HELP!!!

 
0
  #1
Oct 9th, 2009
Hello everyone, can someone help me with this please?
Create class which will create tables in data base (Microsoft Access). About the tables: number of columns, type of data, lenght of the data.
And mantaining the information (the data) in the tables- add data, delete data and edit data.
So far I have codes which are connected with SQL, and I need them in Access. Here are some codes.
  1. import java.sql.*;
  2.  
  3. public class CreateTable{
  4. public static void main(String[] args) {
  5. System.out.println("Table Creation Example!");
  6. Connection con = null;
  7. String url = "jdbc:mysql://localhost:3306/";
  8. String dbName = "jdbctutorial";
  9. String driverName = "com.mysql.jdbc.Driver";
  10. String userName = "root";
  11. String password = "root";
  12. try{
  13. Class.forName(driverName).newInstance();
  14. con = DriverManager.getConnection(url+dbName, userName, password);
  15. try{
  16. Statement st = con.createStatement();
  17. String table = "CREATE TABLE Employee11(Emp_code integer, Emp_name varchar(10))";
  18. st.executeUpdate(table);
  19. System.out.println("Table creation process successfully!");
  20. }
  21. catch(SQLException s){
  22. System.out.println("Table all ready exists!");
  23. }
  24. con.close();
  25. }
  26. catch (Exception e){
  27. e.printStackTrace();
  28. }
  29. }
  30. }
I can post more codes but they're all with SQL.
Any help?
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 36
Reputation: didi00 is an unknown quantity at this point 
Solved Threads: 0
didi00 didi00 is offline Offline
Light Poster
 
0
  #2
Oct 9th, 2009
Will this work?:
  1. import java.sql.*;
  2.  
  3. public class dbAccess
  4. {
  5. public static void main(String[] args)
  6. {
  7. try
  8. {
  9. Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  10. String database =
  11. "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=myDB.mdb;";
  12. Connection conn = DriverManager.getConnection(database, "", "");
  13. Statement s = conn.createStatement();
  14.  
  15. // create a table
  16. String tableName = "myTable" + String.valueOf((int)(Math.random() * 1000.0));
  17. String createTable = "CREATE TABLE " + tableName +
  18. " (id Integer, name Text(32))";
  19. s.execute(createTable);
  20.  
  21. // enter value into table
  22. for(int i=0; i<25; i++)
  23. {
  24. String addRow = "INSERT INTO " + tableName + " VALUES ( " +
  25. String.valueOf((int) (Math.random() * 32767)) + ", 'Text Value " +
  26. String.valueOf(Math.random()) + "')";
  27. s.execute(addRow);
  28. }
  29.  
  30. // Fetch table
  31. String selTable = "SELECT * FROM " + tableName;
  32. s.execute(selTable);
  33. ResultSet rs = s.getResultSet();
  34. while((rs!=null) && (rs.next()))
  35. {
  36. System.out.println(rs.getString(1) + " : " + rs.getString(2));
  37. }
  38.  
  39. // drop the table
  40. String dropTable = "DROP TABLE " + tableName;
  41. s.execute(dropTable);
  42.  
  43. // close and cleanup
  44. s.close();
  45. conn.close();
  46. }
  47. catch(Exception ex)
  48. {
  49. ex.printStackTrace();
  50. }
  51. }
  52. }
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 332
Reputation: quuba is on a distinguished road 
Solved Threads: 54
quuba quuba is offline Offline
Posting Whiz
 
1
  #3
Oct 9th, 2009
Originally Posted by didi00 View Post
Will this work?:
Try yourself.
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 36
Reputation: didi00 is an unknown quantity at this point 
Solved Threads: 0
didi00 didi00 is offline Offline
Light Poster
 
0
  #4
Oct 10th, 2009
The question is this: I work in Eclipse. How to connect Eclipse with Access?
The code is just fine, it has no errors.
The errors that the code is giving me are:
  1. java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Could not find file '(unknown)'.
  2. at sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown Source)
  3. at sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source)
  4. at sun.jdbc.odbc.JdbcOdbc.SQLDriverConnect(Unknown Source)
  5. at sun.jdbc.odbc.JdbcOdbcConnection.initialize(Unknown Source)
  6. at sun.jdbc.odbc.JdbcOdbcDriver.connect(Unknown Source)
  7. at java.sql.DriverManager.getConnection(Unknown Source)
  8. at java.sql.DriverManager.getConnection(Unknown Source)
  9. at dbAccess.main(dbAccess.java:12)
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 332
Reputation: quuba is on a distinguished road 
Solved Threads: 54
quuba quuba is offline Offline
Posting Whiz
 
0
  #5
Oct 10th, 2009
google search --> Database Access Eclipse tutorial
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 332
Reputation: quuba is on a distinguished road 
Solved Threads: 54
quuba quuba is offline Offline
Posting Whiz
 
0
  #6
Oct 10th, 2009
My result:
  1. run:
  2. java.sql.SQLException: [Microsoft][Sterownik ODBC Microsoft Access ] Nie mo?na znale?? pliku '(nieznane)'.//unknown
  3. at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6957)
  4. at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7114)
  5. at sun.jdbc.odbc.JdbcOdbc.SQLDriverConnect(JdbcOdbc.java:3073)
  6. at sun.jdbc.odbc.JdbcOdbcConnection.initialize(JdbcOdbcConnection.java:323)
  7. at sun.jdbc.odbc.JdbcOdbcDriver.connect(JdbcOdbcDriver.java:174)
  8. at java.sql.DriverManager.getConnection(DriverManager.java:582)
  9. at java.sql.DriverManager.getConnection(DriverManager.java:185)
  10. at didi00.dbAccess.main(dbAccess.java:23)
where is your "sun.jdbc.odbc.JdbcOdbcDriver" ?
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 332
Reputation: quuba is on a distinguished road 
Solved Threads: 54
quuba quuba is offline Offline
Posting Whiz
 
0
  #7
Oct 10th, 2009
sun.jdbc.odbc.JdbcOdbcDriver is ok.

I resolved this problem in my post with source code: same theme
http://www.daniweb.com/forums/thread182674.html
good luck
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 36
Reputation: didi00 is an unknown quantity at this point 
Solved Threads: 0
didi00 didi00 is offline Offline
Light Poster
 
0
  #8
Oct 11th, 2009
Thanks. One more question:
Should I create ODBC entry for the data base this way:
Open the Administrative Tools icon in your Control Panel.
Double-click on the Data Sources (ODBC) icon inside.
Choose the System DSN tab.
Click on Add in the System DSN tab.
Select the Microsoft Access Driver. Click Finish.
In the next screen, click Select to locate the database.
Give the database a Data Source Name (DSN).
Click OK.
I'm new in data bases so any help will work.
Thanks
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 120
Reputation: Jocamps is an unknown quantity at this point 
Solved Threads: 7
Jocamps's Avatar
Jocamps Jocamps is offline Offline
Junior Poster
 
0
  #9
Oct 11th, 2009
Originally Posted by didi00 View Post
Thanks. One more question:
Should I create ODBC entry for the data base this way:
Open the Administrative Tools icon in your Control Panel.
Double-click on the Data Sources (ODBC) icon inside.
Choose the System DSN tab.
Click on Add in the System DSN tab.
Select the Microsoft Access Driver. Click Finish.
In the next screen, click Select to locate the database.
Give the database a Data Source Name (DSN).
Click OK.
I'm new in data bases so any help will work.
Thanks
Did it work for you?
Reply With Quote Quick reply to this message  
Reply

Message:



Other Threads in the Java Forum
Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC