Magazine
 
Tips & Tricks
 

list.add(rsmd.getColumnName(i));
}
return list;
}
public static String
getQueryStringToCreateTable(String
tableName, List columnNameList){
Iterator it = columnNameList.iterator();
String st = “create table “+ tableName+”(“;
for(int i=0; i<columnNameList.size();i++){
if(i!=0){
st = st+”,”;
}
st= st+(String)columnNameList.get(i);
st = st+” varchar(10;
}
st = st+”)”;
return st;
}
public static String
getQueryStringToInsertValues(String
tableName, List columnNameList){
Iterator it = columnNameList.iterator();
String st = “insert into “+ tableName+”(“;
String values = “values(“;
for(int i=0; i<columnNameList.size();i++){
if(i!=0){
st = st+”,”;
values = values+”,”;
}
st= st+(String)columnNameList.get(i);
values = values +”?”;
}
st = st+”)”+ values+”)”;
return st;
}
public static void
insertValuesAndExecuteQuery(ResultSet rs,
List columnNameList, PreparedStatement
p_stmt_mysql) throws SQLException{
while (rs.next()) {
for(int i=0;
i<columnNameList.size();i++){
p_stmt_mysql.setString(i+1,
rs.getString((String)columnNameList.get(i)));
}
int n = p_stmt_mysql.executeUpdate();
}
}
}

 

The data in MySQL can be seen below:

 

 

Feb 2008 | Java Jazz Up | 68
previous
index
next
 
View All Topics
All Pages of this Issue
Pages: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,

30
, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53 , 54, 55, 56, 57,

58
, 59, 60, 61, 62, 63 , 64, 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 ,

Download PDF