بســم الله الـرحمــن الرحيــم
ارجو من لديه خبرة في الجافا و
sql server 2005
فقط توضيح طريقة ادراج الصور في جدول عملناه في
sql
طبعا من خلال الجافا
بســم الله الـرحمــن الرحيــم
ارجو من لديه خبرة في الجافا و
sql server 2005
فقط توضيح طريقة ادراج الصور في جدول عملناه في
sql
طبعا من خلال الجافا
السلام عليكم
بصراحة بعد بحث مضني
وجدت لك هذه الوصلة
http://www.roseindia.net/jdbc/save_image.shtml
المشكلة أنها تتحدث عن MySql
أضعها لك لعل وعسى
برجاء إفادتي إن حصلتي على نتيجة
بصراحة لم أستطع التجربة لأني لا أمتلك sqlServer
تحياتي
اذا كنت قد جهزت الجداول ب sql لاستقبال نمط معطيات من نوع image
create table Players (
كل ما بقي عليك هوا عملية الاتصال بقاعدة البيانات ..مثال علاء يفيد لو كان بالmysql لكن فقط اعرف ما هي driver المناسبة
public static Connection getOracleConnection() throws Exception {بالتوفيق ..
الله معك..
المشكلة ان سؤالها متشعب
بالبداية تقول انها تريد ربط sql server ثم تقول ان الجداول مشكلة بالـ sql
على كل حال ارجو ما قدمناه قد يفيد ...الا اذا كنت انا على خطأ ما والله اعلم ...
بالتوفيق
الله معك..
المشكلة شادي أن Sql ليست موحدة للجميع
على ما أظن في SqlServer
فإن صورة هي Image
لكني غير متأكد لهذا نبهتك
تحياتي
السلام عليكــم ورحمـة الله وبركاتــة
الاخوة الافاضل شكرا جزيلا على تعاونكم
اريد توضيح نقطة مهمة
1-انشأت جدول من خلال اسكيوال
وخليت احد الأعمدة من نوع
image
لتهيئتها لإدخال صورة لكني لم ادرج فيه اي صفوف ولا صور
اريد ان يتم هذا من خلال كود جافا
2-هبأت الداتا بيس الي انشأت فيها الجدول للتعامل معها من خلال الجافا
اقصد اتممت عمل خطوات ربط الجافا ب اسكيوال سيرفر 2005
3-بقي فقط عمل كود في الجافا لتعبئة الجدول ( اي ادخال الصور)
رقم 3 فقط هو المطلوب
اتمنى انه الصورة وضحت
وشكرا
جيد ..
هل حاولتي بالمثال الذي قدمه الاخ علاء ...
تحياتي
الله معك..
تم تعديل هذه المشاركة بواسطة shado في 10 نوفمبر 2008 في 18:59
هذا مثال صغير لعملية inserte date بقاعدة بيانات sql من خلال كود جافا
import java.sql.*;
فقط قومي بتغير معلومات انماط المعطيات والقيود على الجداول
بالتوفيق
الله معك..
شكرا جزيلا
زبط معاي كود الاخ علاء
الان فقط احتاج كودجافا لعرض الصور
لاني لما اعمل select
من sql ما تطلع لي الصور لأنها binary
اخ شدو اشكرك على مساعداتك
جزاكم الله خيرا
هذه الفقرة نسختها لك من ملف المساعدة الخاص بjdbc
Large Value Data Types
In earlier versions of SQL Server, working with large-value data types required special handling. Large-value data types are those that exceed the maximum row size of 8 KB. SQL Server 2005 introduces a max specifier for varchar, nvarchar, and varbinary data types to allow storage of values as large as 2^31 bytes. Table columns and Transact-SQL variables can specify varchar(max), nvarchar(max), or varbinary(max) data types.
The primary scenarios for working with large-value types involve retrieving them from a database, or adding them to a database. The following sections describe different approaches to accomplish these tasks.
Retrieving Large-Value Types from a Database
When you retrieve a non-binary large-value data type—such as the varchar(max) data type—from a database, one approach is to read that data as a character stream. In the following example, the executeQuery method of the SQLServerStatement class is used to retrieve data from the database and return it as a result set. Then the getCharacterStream method of the SQLServerResultSet class is used to read the large-value data from the result set.
ResultSet rs = stmt.executeQuery("SELECT TOP 1 * FROM Test1");
rs.next();
Reader reader = rs.getCharacterStream(2);
Note: This same approach can also be used for the text, ntext, and nvarchar(max) data types.
When you retrieve a binary large-value data type—such as the varbinary(max) data type—from a database, there are several approaches that you can take. The most efficient approach is to read the data as a binary stream, as in the following:
ResultSet rs = stmt.executeQuery("SELECT photo FROM mypics");
Rs.next();
InputStream is = rs.getBinaryStream(2);
You can also use the getBytes method to read the data as a byte array, as in the following:
ResultSet rs = stmt.executeQuery("SELECT photo FROM mypics");
Rs.next();
byte [] b = rs.getBytes(2);
Note: You can also read the data as a BLOB. However, this is less efficient than the two methods shown previously.
Adding Large-Value Types to a Database
Uploading large data with the JDBC driver works well for the memory-sized cases, and in the larger-than-memory cases, streaming is the primary option. However, the most efficient way to upload large data is through the stream interfaces.
Using a string or bytes is also an option, as in the following:
PreparedStatement pstmt = con.prepareStatement("INSERT INTO test1 (c1_id, c2_vcmax) VALUES (?, ?)");
pstmt.setInt(1, 1);
pstmt.setString(2, htmlStr);
pstmt.executeUpdate();
Note: This approach can also be used for values that are stored in text, ntext, and nvarchar(max) columns.
If you have an image library on the server and must upload entire binary image files to a varbinary(max) column, the most efficient method with the JDBC driver is to use streams directly, as in the following:
Statement stmt = con.createStatement();
PreparedStatement pstmt = con.prepareStatement("INSERT INTO test1
VALUES( ?, ? )");
FileReader in = new FileReader(new File("CLOBFile20mb.txt");
long len = fileIn.length();
int id = 1;
pstmt.setInt(1,id);
pstmt.setCharacterStream(2, in, (int)len);
pstmt.executeUpdate();
in.close();المشكلة أنه ليس لدي SQLServer لأجرب
حاولي وانظري ما آخر شيء ستصلي إليه
وبإذن الله سنرى حلاً
وأتمنى إن وصلتي لشيء أن تخبرينا
تحياتي
السلام عليكــم ورحمـة الله وبركاتــه
تم عمل الكود ولله الحمد كالتالي :
import java.sql.*;
import java.io.*;
public class saveImage
{
public static void main(String[] args)
{
DB db = new DB();
Connection conn=db.dbConnect(
"jdbc:sqlserver://localhost:1433;DatabaseName=mayada","noha","123");
db.insertImage(conn);
db.getImageData(conn);
}
}
class DB
{
public DB() {}
public Connection dbConnect( String db_connect_string,
String db_userid, String db_password)
{
try
{
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
Connection conn = DriverManager.getConnection(
db_connect_string, db_userid, db_password);
System.out.println("connected");
return conn;
}
catch (Exception e)
{
e.printStackTrace();
return null;
}
}
public void insertImage(Connection conn)
{
int len;
String query;
PreparedStatement pstmt;
try
{
query = ("insert into dbo.images VALUES(?,?,?)");
File file = new File("C:/Users/RMC/Desktop/images11/1.jpg");
FileInputStream fis = new FileInputStream(file);
pstmt = conn.prepareStatement(query);
pstmt.setString(1,"mayada");
pstmt.setString(3,"qq");
len = (int)file.length();
// Method used to insert a stream of bytes
pstmt.setBinaryStream(2, fis, len);
pstmt.executeUpdate();
}
catch (Exception e)
{
e.printStackTrace();
}
}
public void getImageData(Connection conn)
{
byte[] fileBytes;
String query = "select [image name] from dbo.images ";
try
{
Statement state = conn.createStatement();
ResultSet rs = state.executeQuery(query);
if (rs.next())
{
fileBytes = rs.getBytes(1);
FileOutputStream targetFile=new FileOutputStream("c://filepath//new.JPG");
targetFile.write(fileBytes);
targetFile.close();
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
};شكرا لكل من ساعدني