Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Help - Java and Update Query

947967Jan 22 2013 — edited Jan 14 2015
I'm using a Button for update an Parodox db file
my code is

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
try {
Connection paradoxCon = paradox.createConnection();
Results res = new Results();
res.getAll();
if (res.allRes.isEmpty()) {
JOptionPane.showMessageDialog(mainPanel, "There are no Finished or Postponed Games!", "Error", JOptionPane.ERROR_MESSAGE);
} else {
int y = res.allRes.size();
for (int x = 0; x < y; x = x + 1) {
try {
if (res.getAll().get(x).Reversed == 0) {
if (res.getAll().get(x).Status.equals("Fin")) {
String sql = "UPDATE Kvote SET _45_d = '" + res.getAll().get(x).HThome + "', _45_g = '" + res.getAll().get(x).HTaway + "', _90_d= '" + res.getAll().get(x).FThome + "', _90_g = '" + res.getAll().get(x).FTaway + "', Ok='Y' WHERE Kolo = '" + res.getAll().get(x).tRound + "' AND Sifra='" + res.getAll().get(x).TID + "'";
PreparedStatement ps = paradoxCon.prepareStatement(sql);
ps.executeUpdate();
}
if (res.getAll().get(x).Status.equals("Post")) {
String sql = "UPDATE Kvote SET _45_d = '" + res.getAll().get(x).HThome + "', _45_g = '" + res.getAll().get(x).HTaway + "', _90_d= '" + res.getAll().get(x).FThome + "', _90_g = '" + res.getAll().get(x).FTaway + "', Ok='O' WHERE Kolo = '" + res.getAll().get(x).tRound + "' AND Sifra='" + res.getAll().get(x).TID + "'";
PreparedStatement ps = paradoxCon.prepareStatement(sql);
ps.executeUpdate();
}
}
if (res.getAll().get(x).Reversed == 1) {
if (res.getAll().get(x).Status.equals("Fin")) {
String sql = "UPDATE Kvote SET _45_d = '" + res.getAll().get(x).HTaway + "', _45_g = '" + res.getAll().get(x).HThome + "', _90_d= '" + res.getAll().get(x).FTaway + "', _90_g = '" + res.getAll().get(x).FThome + "', Ok='Y' WHERE Kolo = '" + res.getAll().get(x).tRound + "' AND Sifra='" + res.getAll().get(x).TID + "'";
PreparedStatement ps = paradoxCon.prepareStatement(sql);
ps.executeUpdate();
}
if (res.getAll().get(x).Status.equals("Post")) {
String sql = "UPDATE Kvote SET _45_d = '" + res.getAll().get(x).HTaway + "', _45_g = '" + res.getAll().get(x).HThome + "', _90_d= '" + res.getAll().get(x).FTaway + "', _90_g = '" + res.getAll().get(x).FThome + "', Ok='O' WHERE Kolo = '" + res.getAll().get(x).tRound + "' AND Sifra='" + res.getAll().get(x).TID + "'";
PreparedStatement ps = paradoxCon.prepareStatement(sql);
ps.executeUpdate();
}
}
} catch (Exception ex) {
System.out.println(ex);
}
}
}
res.getAll().clear();
} catch (ParseException ex) {
Logger.getLogger(AutoResultsImporterView.class.getName()).log(Level.SEVERE, null, ex);
}
}



but i'm getting an Exception when i try to update table

java.sql.SQLException: [Microsoft][ODBC Paradox Driver] Operation must use an updateable query.
java.sql.SQLException: [Microsoft][ODBC Paradox Driver] Operation must use an updateable query.
java.sql.SQLException: [Microsoft][ODBC Paradox Driver] Operation must use an updateable query.


im connecting to database using this code:


public class paradox {

public static Connection createConnection() {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
Connection conn = DriverManager.getConnection("jdbc:odbc:TOTO-Ticket", "infos", "infos");
return conn;
} catch (Exception e) {
System.out.println(e);
System.exit(0);
return null;
}
}
}

Comments

unknown-7404
Answer

It looks like in Java it is preferred to have the connection pool set up on the server (tomcat).

Not quite - the connection pool (and any other Java code) will be 'set up' within the JVM instance. That will be on whatever machine you execute 'java.exe' on.

So my question is if I deployed 5 distinct applications on to a tomcat web server each (referencing their own UCP java and OJDBC jar) when the application's startup, do each application create its own separate connection pool?

See my first comment above.

1. you use 'java.exe' to create a JVM - a JVM is a container - it does NOT interact with anything outside that container unless you write code to do so.

2. you run ONE APPLICATION on that JVM

3. that application can create as many connection pools as it wants in that JVM

4. that application can be multi-threaded so each thread can do whatever it wants/needs to do including creating pools (see #3)

5. multiple applications launch their own JVMs running a single app so for each app just go back and see #2, #3 and #4

Marked as Answer by mlov83 · Sep 27 2020
mlov83

Thanks for the response RP0428, that makes a ton of sense, just to make sure I understand in Tomcat I wouldn't execute a java.exe are you referring to .net in your above reply? follow up question, do you think tomcat would do the same? The reason I ask is because I've been reading a lot about class loaders and how if I have to projects with the same exact class names they will clash. Sorry , If I'm confusing apples and oranges here, I'm just trying to be thorough and make sure I understand.

unknown-7404

Tomcat is launching the JVM and creating multi-threaded 'apps' within it. Each of those 'apps' can have its own connection pool and there won't be any crosstalk/access between the apps.

1 - 3
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Feb 19 2013
Added on Jan 22 2013
5 comments
248 views