aspose file tools*
The moose likes JDBC and the fly likes help with a sql statement Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "help with a sql statement" Watch "help with a sql statement" New topic
Author

help with a sql statement

ben riches
Ranch Hand

Joined: Nov 08, 2002
Posts: 126
hello everyone i hope someone can help me.
i have this code which is below.
what the code is doing is testing to see if any other strings are equal to st1 and if they are get there values from the hashtable.(which is ok)
But now i want set a sql statement so that the keys of all the values that are equal to st1 are put in the sql statement as column names but as you can see i am getting a bit stuck with my code could someone please help me?
thanks for yr time
ben
import java.io.*;
import java.util.*;
import java.lang.*;
import java.sql.*;
public class has21 {
public static void main(String[] args) {
ArrayList arr = new ArrayList();
Hashtable hash = new Hashtable();
String a = "firstname"; //column names
String b = "lastname";
String c = "id";
String d = "adress1";
String k = "phone";
String f = "county";
String g = "post code";
String h = "country";
String i = "goods in";
String j = "goods out";
String st1 = "ben";
String st2 = "ben"; //table names
String st3 = "alex";
String st4 = "alex";
String st5 = "matt";
String st6 = "matt";
String st7 = "mum";
String st8 = "mum";
String st9 = "dad";
String st10 = "ben";
hash.put(a, st1);
hash.put(b, st2);
hash.put(c, st3);
hash.put(d, st4);
hash.put(k, st5);
hash.put(f, st6);
hash.put(g, st7);
hash.put(h, st8);
hash.put(i, st9);
hash.put(j, st10);
if(hash.containsValue(st1)) {
Enumeration e = hash.keys();
while (e.hasMoreElements()) {
String tempkey = (String) e.nextElement();
String tempvalue = (String) hash.get(tempkey);
if(tempvalue.equals(st1)) {
arr.add(tempkey);
try {
String data = "jdbc dbc:myProject";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection(data,"","");
String x = "Insert INTO st1"(
for (int t = 0; t < arr.size(); t++){
x = x + "," VALUES(?, ?, ?)")";
}
PreparedStatement prepStmt = con.prepareStatement(x);
prepStmt.setString(1, "hello");
prepStmt.setString(2, "hi");
prepStmt.setString(3, "bye");
prepStmt.executeUpdate();
prepStmt.close();
} catch (Exception e1) {
System.err.println("Got an exception! ");
System.err.println(e1.getMessage());
}

}
}
}
}
}
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: help with a sql statement
 
Similar Threads
how can i pull out every number from a vector
help with some code.
help with a statement
How can you do this
help with testing a hashtable