inserting a record into Access database

Hi guys i am having problem with the insertion of a record in to a Access database!!!!

It is not given any exceptions or errors but simply does not insert it!!!

Here is my code!!

import java.sql.*;

class access

{

public static void main(String a[])

{

// Set default values for the command line args\par

Connection connection;// Connection to the database

Statement statement;// Statement object for queries

String user= "";

String password = "";

String url= "jdbc:odbc:db1";

String driver= "sun.jdbc.odbc.JdbcOdbcDriver";

try

{

Class.forName(driver);// Load the driver

connection = DriverManager.getConnection(url, user, password);

if(a.length !=0)

{

PreparedStatement ps = connection.prepareStatement("insert into search(Orgname,Website) values(?,?)");

ps.setString(1,a[0]);

ps.setString(2,a[1]);

int res = ps.executeUpdate();

System.out.println("i am in" + " the output result no ="+res );

ps.close();

}

}

catch(ClassNotFoundException cnfe)

{

System.err.println(cnfe);// Driver not found

}

catch(SQLException sqle)

{

System.err.println(sqle); // error connection to database

}

}

}

-DK

[1337 byte] By [decaynan] at [2007-9-26 1:59:00]
# 1
from what I've seen in this forum it seems to be a fairly common problem. if you call a Select statement following the insert, it usually forces the insert to mysteriously appear. good old M$Jamie
jlrober at 2007-6-29 3:17:34 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 2

sounds like if you close the connection, it might commit and that may work?

> from what I've seen in this forum it seems to be a

> fairly common problem. if you call a Select statement

> following the insert, it usually forces the insert to

> mysteriously appear.

>

> good old M$

>

> Jamie

mchan0 at 2007-6-29 3:17:34 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 3
closing the connection workedthanx!!!!-D.K
decaynan at 2007-6-29 3:17:34 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 4
Take jlrober's approach.It will be much better for performance!Do a dummy select after you completed your other statements, like e.g.:ResutlSet rs = stmt.executeQuery( "select 123" );rs.close();
Hartmut at 2007-6-29 3:17:34 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 5
I find that disconnecting then reconnecting (in my case) has a lot more overhead and is exponentially more time consuming than doing a simple SELECT statement after the INSERT.Jamie
jlrober at 2007-6-29 3:17:34 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 6
use a real database!postgres is free and good.instantDB is all java
mchan0 at 2007-6-29 3:17:34 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 7
Interbase is great.A lot of people like mysql.But in most cases you are not free to choose the database. If there are already data existing, you simply must use them.So it's fine if there's a way to do it even with Access ;-)
Hartmut at 2007-6-29 3:17:34 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 8
Yes Mysql is a very good and tiny database.
srinivasm21 at 2007-6-29 3:17:34 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 9
http://apachetoday.com/news_story.php3?ltsn=2000-08-14-008-01-PR-MR-SW
mchan0 at 2007-6-29 3:17:34 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 10

This is kind of out of track, but about mysql, if I use the library, I wonder if that would force me to ship my source code or not. The license said if it's "using" instead of "deriving" then my code is not GNU. However, there is some linking here. For java, it's class file so no source is included, however, in c++ for example, when you include a header file, does that means I already link my code with existing code? Then there is a clause say that if there are 10 lines or less (or something like that) then it's ok. What a mess with this GNU thing. Can some of you clear this up for me, please. Thank you in advance.

Another thing about MySql, I tried it, and it works, however, it's like hackers' tool, at least for the c++ library. They don't have move next or things like that (you increase the iterator instead), it looks real different from API like dao or ado or jdbc. Anyone bother give me some comment?

VH

vy_ho at 2007-6-29 3:17:34 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 11

I'm not sure, but I think, linking your code against a library is considered as "using", not "deriving", since you don't change the library itself.

It should not matter, whether you link staticly or dynamicly or only ship a file to use it with a program (like reading an image).

Otherwise: how could anyone "use" a static library without linking his code to it?

If - like you described - some features are "too low level" for your taste (I would feel similiar), I can only tell my experience:

With InterBase you have a GPL'd DBMS which is available in fully mainted shape. You can download the executables and use it like a commercial DBMS - no touch with libraries or the sources, if you don't want.

IBConsole is a tool that can be compared with MS SQLServer's Enterprise Manager, I think!

InterClient/InterServer offers a JDBC type 3 driver.

There are also some ODBC drivers for it at the market.

This is real Open Source!

What do you want more?

Hartmut at 2007-6-29 3:17:34 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...