无法使用android在ms sql数据库中插入记录
我正在尝试使用ftp将图像上载到web文件夹,它工作正常,但当我尝试插入相应图像的记录时,它不起作用,程序在尝试块之前会跳转。我已使用每个循环上载图像以及获取图像的文件名。下面是用于插入的代码以及上传图片。 因此,当我尝试使用for each循环上载10多个图像时,我无法插入记录,但ftp图像上载工作正常。 我需要知道我在哪里犯了错误。有人能告诉我我在哪里犯了错误吗无法使用android在ms sql数据库中插入记录,android,image,activerecord,ftp,insert,Android,Image,Activerecord,Ftp,Insert,我正在尝试使用ftp将图像上载到web文件夹,它工作正常,但当我尝试插入相应图像的记录时,它不起作用,程序在尝试块之前会跳转。我已使用每个循环上载图像以及获取图像的文件名。下面是用于插入的代码以及上传图片。 因此,当我尝试使用for each循环上载10多个图像时,我无法插入记录,但ftp图像上载工作正常。 我需要知道我在哪里犯了错误。有人能告诉我我在哪里犯了错误吗 public class DisplayImageActivity extends Activity{ private Image
public class DisplayImageActivity extends Activity{
private ImageAdapter imageAdapter;
String call, db, un, passwords;
String orig;
String names;
String icore;
String imagename;
Connection con;
ResultSet rs;
ConnectionClass connectionclass;
String imagenametag;
@SuppressLint("NewApi")
private Connection ConnectionHelper(String user, String password,
String database, String server) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
.permitAll().build();
StrictMode.setThreadPolicy(policy);
Connection connection = null;
String ConnectionURL = null;
try {
Class.forName("net.sourceforge.jtds.jdbc.Driver");
ConnectionURL = "jdbc:jtds:sqlserver://" + server + ";"
+ "databaseName=" + database + ";user=" + user
+ ";password=" + password + ";";
connection = DriverManager.getConnection(ConnectionURL);
} catch (SQLException se) {
Log.e("ERRO", se.getMessage());
} catch (ClassNotFoundException e) {
Log.e("ERRO", e.getMessage());
} catch (Exception e) {
Log.e("ERRO", e.getMessage());
}
return connection;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.gridview);
sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri
.parse("file://"
+ Environment.getExternalStorageDirectory())));
connectionclass = new ConnectionClass();
call = connectionclass.getip();
un = connectionclass.getun();
passwords = connectionclass.getpassword();
db = connectionclass.getdb();
// connect = ConnectionHelper(un, passwords, db, call);
GridView gridview = (GridView) findViewById(R.id.gridview);
imageAdapter = new ImageAdapter(this);
gridview.setAdapter(imageAdapter);
String ExternalStorageDirectoryPath = Environment
.getExternalStorageDirectory()
.getAbsolutePath();
String targetPath = ExternalStorageDirectoryPath + "/JCG Camera";
Toast.makeText(getApplicationContext(), targetPath, Toast.LENGTH_LONG).show();
File targetDirector = new File(targetPath);
File[] files = targetDirector.listFiles();
orig = "/site1/Image/";
for(File file1:files){
imageAdapter.add(file1.getAbsolutePath());
if(!file1.isFile())continue;
String msg = "";
String[]bits=file1.getName().split("_");
// imagenametag = file1.getName();
// String[] parts = imagenametag.split("_");
names = bits[0];
icore = bits[1];
imagename = file1.getName();
try {
con = ConnectionHelper(un, passwords, db, call);
if (con == null) {
msg = "Error in connection with SQL server";
} else {
String commands = "Insert into Image(Image_Tag,Image_Name,orig_img_path) values ('" + names + "','" + imagename + "','" + orig + "')";
PreparedStatement preStmt = con.prepareStatement(commands);
preStmt.executeUpdate();
msg = "Info Saved";
new FTPFileUpload(this).execute(
FTPConstants.SERVER,
FTPConstants.USER_NAME,
FTPConstants.PASSWORD,
file1.getAbsolutePath(),
"/site1/Image/" + file1.getName());
}
} catch (SQLIntegrityConstraintViolationException ec) {
msg = "Image Taken Already";
} catch (IOError ex) {
// TODO: handle exception
msg = ex.getMessage().toString();
Log.d("skool", msg);
} catch (AndroidRuntimeException ex) {
msg = ex.getMessage().toString();
Log.d("skool", msg);
} catch (NullPointerException ex) {
msg = ex.getMessage().toString();
Log.d("skool", msg);
} catch (Exception ex) {
// msg= ""+spstud.getSelectedItem()+"'s Record has been saved already for"+date.getText().toString()+"";
Log.d("skool", msg);
}
Toast.makeText(DisplayImageActivity.this, msg, Toast.LENGTH_LONG).show();
}
}
@Override
public void onBackPressed() {
super.onBackPressed();
String ExternalStorageDirectoryPath = Environment
.getExternalStorageDirectory()
.getAbsolutePath();
String targetPath = ExternalStorageDirectoryPath + "/JCG Camera";
// Toast.makeText(getApplicationContext(), targetPath, Toast.LENGTH_LONG).show();
File targetDirector = new File(targetPath);
File[] files = targetDirector.listFiles();
for (File file : files) {
file.delete();
}
Intent i=new Intent(DisplayImageActivity.this,ListMain.class);
startActivity(i);
DisplayImageActivity.this.finish();
}
}您能否更具体地说明当您尝试插入超过10张图像时会发生什么情况?你有错误吗?撞车?异常?当插入10多个图像时,图像会被很好地上载,但插入查询不起作用。循环会在try块之前跳转。即使上载2个图像,插入查询也不会在SQL区域周围插入一些断点。事实上,您上传的所有图像都表明循环工作正常,并且您的SQL块没有抛出异常(否则图像的循环将被破坏)。要排除SQL字符串本身,请尝试直接在服务器上使用它,看看是否有错误。我不明白。你可以用一些示例解释一下你不明白什么?你能更具体地说明当你尝试插入10多个图像时会发生什么情况吗?你有错误吗?撞车?异常?当插入10多个图像时,图像会被很好地上载,但插入查询不起作用。循环会在try块之前跳转。即使上载2个图像,插入查询也不会在SQL区域周围插入一些断点。事实上,您上传的所有图像都表明循环工作正常,并且您的SQL块没有抛出异常(否则图像的循环将被破坏)。要排除SQL字符串本身,请尝试直接在服务器上使用它,看看是否有错误。我不明白,你能用一些例子解释一下吗?你不明白什么?