Results 1 to 6 of 6
- 07-13-2010, 01:03 PM #1
Member
- Join Date
- Jul 2010
- Posts
- 1
- Rep Power
- 0
connect java to MS Access Database
Hi,
I am newbie to java programming. Now i am trying to connect the java program to Ms access database. So Far i have the following coding which i developed to connect to MS Access database. I am trying to change the name in the database table using the update query. Is this Code correct? And also Please tell me how to run the java program which has database connection?
Please Anyone here help me out in this regard...PHP Code:import java.sql.*; class a { public static void changelastname() { String sql = "update employee set lname='yyy' where id=1"; st.executeUpdate(sql); System.out.println("Table updated."); } public static void main(String[] args) { try { System.out.println(“Begining conn”); Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”); String accessFileName = “company”; String connURL=”jdbc:odbc:;DRIVER=Microsoft Access Driver (*.mdb);DBQ=”+accessFileName+”.mdb;PWD=”; Connection con = DriverManager.getConnection(connURL, “”,”"); System.out.println(“Conn done succesfully”); } changelastname(); stmt.close(); con.close(); } catch (Exception err) { System.out.println(“ERROR: ” + err); } } }
- 07-13-2010, 01:12 PM #2
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Did you run this code on your IDE?
- 07-14-2010, 09:16 AM #3
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
"Is this code correct?" is not a good question.
You need to tell us what's wrong...we're not going to run it, but we can bug fix if you tell us what the bug is.
For starters does it compile?
- 07-14-2010, 10:48 AM #4
Member
- Join Date
- Mar 2010
- Location
- New Delhi,Vadodara
- Posts
- 50
- Rep Power
- 0
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("Jdbc:Odbc:bank");
Statement st=con.createStatement();
bank is the DSN Name.
- 07-14-2010, 12:29 PM #5
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
Okay? And this has to do with what? Especially since the OP is obviously inteding to make a DSNLess connection which is possible and inifinitly more flexible.
- 07-14-2010, 01:53 PM #6
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,408
- Blog Entries
- 7
- Rep Power
- 17
Similar Threads
-
Java SE Database Access
By appdevman in forum New To JavaReplies: 1Last Post: 06-23-2010, 05:34 PM -
how to connect java to MS Access database
By Manfizy in forum New To JavaReplies: 4Last Post: 12-24-2009, 04:50 PM -
java with access database
By ashin in forum SWT / JFaceReplies: 4Last Post: 07-12-2009, 05:04 PM -
Help with Java application to connect to a database
By coco in forum JDBCReplies: 3Last Post: 09-18-2008, 03:07 PM -
How to connect a Java program with MySQL database?
By Ms.Ranjan in forum JDBCReplies: 2Last Post: 06-12-2008, 07:09 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks