我写了两个类, 功能是大概如下:
有两个表:
A.  products 
B.  meta_tags_products_descriptionA的products_id 是B表的外键+主键, 所以, 要在B表插入数据, id应该从A表中读出id.
问题是:
我本地数据库写没问题, 一上远程就出问题了, 上网查是说要存储过程, 但是, 个人写的代码太死了, 现在改不知道怎么改, 望有高手帮忙改下.package com.jj;import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Random;public class MySQL { private static FileReader fr = null;
private static BufferedReader br = null;
private static FileWriter fw = null;
private static BufferedWriter bw = null;
private static int i = 0;
private String text[] = new String[3];
static TestMysqlConnection tmc = null;
static String id[];

public static void main(String []args){
MySQL mysql = new MySQL();
TestMysqlConnection tmc = new TestMysqlConnection();
id = tmc.getProductsId();
mysql.getText();

}

public  String[] getText() {
String str[] = new String[3];
String text[] = new String[3000];
String word[] = new String[10]; try {
fr = new FileReader(".\\src\\sql\\keywords.txt");
br = new BufferedReader(fr); 
// fw = new FileWriter(".\\src\\sql\\keywordsresult.txt");
// bw = new BufferedWriter(fw);   

int j = 0;
while ( br.ready()) {
i = i %3;
// str[i] = br.readLine();
word = br.readLine().split(",");
if(null ==word || word.equals(""))
continue;
str[i] = word[0];
if(i == 2){

text[0] = str[0] + " | " + str[1] + " | " + str[2] + " - BrideOfTheSea.com";
text[1] =  str[0] + ", " + str[1] + ", " + str[2] + ", " + 
"Wedding Dresses Discount, Discount Bridal Gowns";
text[2] = "discount for " + text[1] + " from wholesale: Wedding Dresses Discount, Cheap Wedding Gowns, " +
"Discount Bridal Gowns, China wedding dresses at www.BrideOfTheSea.com";
if(null ==id[j] || id[j].equals(""))
break;
exesql(id[j], text);
j++;


}
i++;
}
br.close();
fr.close();
// bw.close();
// fw.close();
} catch (IOException e) {
e.printStackTrace();
}
return text;
} public boolean exesql(String id, String text[]){
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
System.out.println("第" + id + "个" + "内容: ");
for(int i=0; i< 3; i++)
System.out.println(text[i]);



try {
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql://localhost/sea?user=root&password=root");
stmt = conn.createStatement();
// stmt.executeUpdate("insert into meta_tags_products_description values('1', '1', '1232', '12321', '123213');");
stmt.executeUpdate("insert into meta_tags_products_description values('"+ id + "', '1', '"+ text[0] +"','"+ text[1] +"','"+ text[2] + "');");
// System.out.println("insert into meta_tags_products_description values('"+ id + "', '1', '"+ text[0] +"','"+ text[1] +"','"+ text[2] + "');"); } catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException ex) {
System.out.println("SQLException: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("VendorError: " + ex.getErrorCode());
} finally {
try {
if(rs != null) {
rs.close();
rs = null;
}
if(stmt != null) {
stmt.close();
stmt = null;
}
if(conn != null) {
conn.close();
conn = null;
}
} catch (SQLException e) {
e.printStackTrace();
}
}
return false; }
}package com.jj;
import java.sql.*;public class TestMysqlConnection { private static String idstr[] = new String[10000];
private static String text[]; public  String[] getProductsId() {
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
int i = 0; try {
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql://localhost/sea?user=root&password=root");
stmt = conn.createStatement(); rs = stmt.executeQuery("select * from products");
while (rs.next()) {
idstr[i] = rs.getString("products_id");
// System.out.println(idstr[i]);
i++;
} } catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException ex) {
System.out.println("SQLException: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("VendorError: " + ex.getErrorCode());
} finally {
try {
if(rs != null) {
rs.close();
rs = null;
}
if(stmt != null) {
stmt.close();
stmt = null;
}
if(conn != null) {
conn.close();
conn = null;
}
} catch (SQLException e) {
e.printStackTrace();
}
}
return idstr;
}}