| | |
NEED HELP!!!
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Apr 2008
Posts: 36
Reputation:
Solved Threads: 0
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.
I can post more codes but they're all with SQL.
Any help?
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.
Java Syntax (Toggle Plain Text)
import java.sql.*; public class CreateTable{ public static void main(String[] args) { System.out.println("Table Creation Example!"); Connection con = null; String url = "jdbc:mysql://localhost:3306/"; String dbName = "jdbctutorial"; String driverName = "com.mysql.jdbc.Driver"; String userName = "root"; String password = "root"; try{ Class.forName(driverName).newInstance(); con = DriverManager.getConnection(url+dbName, userName, password); try{ Statement st = con.createStatement(); String table = "CREATE TABLE Employee11(Emp_code integer, Emp_name varchar(10))"; st.executeUpdate(table); System.out.println("Table creation process successfully!"); } catch(SQLException s){ System.out.println("Table all ready exists!"); } con.close(); } catch (Exception e){ e.printStackTrace(); } } }
Any help?
•
•
Join Date: Apr 2008
Posts: 36
Reputation:
Solved Threads: 0
0
#2 Oct 9th, 2009
Will this work?:
Java Syntax (Toggle Plain Text)
import java.sql.*; public class dbAccess { public static void main(String[] args) { try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); String database = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=myDB.mdb;"; Connection conn = DriverManager.getConnection(database, "", ""); Statement s = conn.createStatement(); // create a table String tableName = "myTable" + String.valueOf((int)(Math.random() * 1000.0)); String createTable = "CREATE TABLE " + tableName + " (id Integer, name Text(32))"; s.execute(createTable); // enter value into table for(int i=0; i<25; i++) { String addRow = "INSERT INTO " + tableName + " VALUES ( " + String.valueOf((int) (Math.random() * 32767)) + ", 'Text Value " + String.valueOf(Math.random()) + "')"; s.execute(addRow); } // Fetch table String selTable = "SELECT * FROM " + tableName; s.execute(selTable); ResultSet rs = s.getResultSet(); while((rs!=null) && (rs.next())) { System.out.println(rs.getString(1) + " : " + rs.getString(2)); } // drop the table String dropTable = "DROP TABLE " + tableName; s.execute(dropTable); // close and cleanup s.close(); conn.close(); } catch(Exception ex) { ex.printStackTrace(); } } }
•
•
Join Date: Apr 2008
Posts: 36
Reputation:
Solved Threads: 0
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:
The code is just fine, it has no errors.
The errors that the code is giving me are:
Java Syntax (Toggle Plain Text)
java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Could not find file '(unknown)'. at sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown Source) at sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source) at sun.jdbc.odbc.JdbcOdbc.SQLDriverConnect(Unknown Source) at sun.jdbc.odbc.JdbcOdbcConnection.initialize(Unknown Source) at sun.jdbc.odbc.JdbcOdbcDriver.connect(Unknown Source) at java.sql.DriverManager.getConnection(Unknown Source) at java.sql.DriverManager.getConnection(Unknown Source) at dbAccess.main(dbAccess.java:12)
•
•
Join Date: Nov 2008
Posts: 332
Reputation:
Solved Threads: 54
0
#6 Oct 10th, 2009
My result:
where is your "sun.jdbc.odbc.JdbcOdbcDriver" ?
Java Syntax (Toggle Plain Text)
run: java.sql.SQLException: [Microsoft][Sterownik ODBC Microsoft Access ] Nie mo?na znale?? pliku '(nieznane)'.//unknown at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6957) at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7114) at sun.jdbc.odbc.JdbcOdbc.SQLDriverConnect(JdbcOdbc.java:3073) at sun.jdbc.odbc.JdbcOdbcConnection.initialize(JdbcOdbcConnection.java:323) at sun.jdbc.odbc.JdbcOdbcDriver.connect(JdbcOdbcDriver.java:174) at java.sql.DriverManager.getConnection(DriverManager.java:582) at java.sql.DriverManager.getConnection(DriverManager.java:185) at didi00.dbAccess.main(dbAccess.java:23)
•
•
Join Date: Nov 2008
Posts: 332
Reputation:
Solved Threads: 54
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
I resolved this problem in my post with source code: same theme
http://www.daniweb.com/forums/thread182674.html
good luck
•
•
Join Date: Apr 2008
Posts: 36
Reputation:
Solved Threads: 0
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
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
0
#9 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
![]() |
Other Threads in the Java Forum
- Previous Thread: netbeans problem
- Next Thread: writing to a file
| Thread Tools | Search this Thread |
Tag cloud for Java
android animated api appinventor apple applet application arguments array arrays automation binary bluetooth c++ chat chatprogramusingobjects chooser class classes client code codesnippet compare compiler component coordinates database doctype draw eclipse editor error event exception file fractal freeze game givemetehcodez graphics gui guidancer health helpwithhomework html ide image input int integer j2me java javaprojects jmf jni jpanel jtable julia linux list login loop map method methods mobile netbeans newbie nonstatic number oracle page plazmic print problem program programming project recursion scanner screen sell server set sharepoint size sms socket sort sourcelabs sql string swing system test testautomation threads time tree windows





