Click to See Complete Forum and Search --> : anyone with Java experience?
include_me
02-10-2007, 01:04 PM
Hi there,
Im a uni student studying a computer science degree, I have been set an assignment to design develop and implement a system which runs of a MS Access DB, We have to create a Java App for the "client" to view details and add details to the DB and We also have to create a website that allows people to add their details and view details in the DB. The question I have is, is it possile to access a Microsoft Access DB from a Java Applet from a normal HTML webpage? or do I have to connect to it using ASP.net? Im used to PHP so im a tad confused..
Any information or ideas would be great..
Thanks,
Chris
snailfur
02-14-2007, 02:31 PM
Hello,
I have yet to use Java with MS Access although by a quick Google search Im guessing its basically the same as all popular databases output results in ODBC form, which is just a global form of database output that everyone follows to making it easy to use the data. Just like what XML does for the web.
My Google Search: http://www.google.com/search?hl=en&safe=off&q=Java+connecting+to+MS+Access+DB&btnG=Search
Here is a great article for JDBC (Java's ODBC accessing extension Im guessing) I found by searching Google: http://www.developer.com/db/article.php/10920_3571661_1
And here is some code taken from page 3 of that article:
// JDBC|Test – complete code
public class JDBCTest {
public static void main(String args[]){
RunDB runDB = new RunDB();
try{
runDB.loadDriver();
runDB.makeConnection();
runDB.buildStatement();
runDB.executeQuery();
}catch(Exception e){
e.printStackTrace();
}
}
}
//RunDB
import java.sql.*;
public class RunDB {
Connection connection;
Statement statement;
public void loadDriver() throws ClassNotFoundException{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
public void makeConnection() throws SQLException {
connection=
DriverManager.getConnection("jdbc:odbc:purchaseOrder")
}
public void buildStatement() throws SQLException {
statement = connection.createStatement();
}
public void executeQuery() throws SQLException {
boolean foundResults =
statement.execute("SELECT * FROM Transaction");
if(foundResults){
ResultSet set = statement.getResultSet();
if(set!=null) displayResults(set);
}else {
connection.close();
}
}
void displayResults(ResultSet rs) throws SQLException {
ResultSetMetaData metaData = rs.getMetaData();
int columns=metaData.getColumnCount();
String text="";
while(rs.next()){
for(int i=1;i<=columns;++i) {
text+="<"+metaData.getColumnName(i)+">";
text+=rs.getString(i);
text+="</"+metaData.getColumnName(i)+">";
text+="n";
}
text+="n";
}
System.out.println(text);
}
}
As you can see, its fairly like PHP, obviously function names are different and syntax is different, although you can get the general idea if you are already familiar with PHP.
For example:
statement.execute("SELECT * FROM Transaction");
"execute()" in PHP would be "mysql_query()".
As for applets. They can be useful for alot of things, although as soon as you try to access things outside the applet, Java can be a real pain. Im not sure about security rights for JDBC, although I know filesystem is a pain, you need to setup a certificate the user needs to accept.
If you also have to produce a website, why not use PHP for that?
Hope that helps somewhat.
PHP Builder
Copyright WebMediaBrands Inc. All Rights Reserved.