Tutorials to .com

Tutorials to .com » Jsp » Database » Through jdbc-odbc to Access database OLE types of table to insert data examples

Through jdbc-odbc to Access database OLE types of table to insert data examples

Print View , by: iSee ,Total views: 15 ,Word Count: 376 ,Date: Sun, 19 Apr 2009 Time: 2:37 AM

/ **
* Description:
* Jdbc-odbc through the access database to insert a picture, or a mess of paper will do
* Note that to be wrong with DataInputStream
*
/
import java.sql .*;
import java.io.FileInputStream;
public class sss
(
public static void main (String args [])
(
try
(
/ / Connect ACCESS database using the connection string here Oh
Class.forName ( "sun.jdbc.odbc.JdbcOdbcDriver"). NewInstance ();
java.sql.Connection conctn = DriverManager.getConnection (
"jdbc: odbc:;" +
"DRIVER = Driver do Microsoft Access (*. mdb);" +
"UID = admin;" +
"UserCommitSync = Yes;" +
"Threads = 3;" +
"SafeTransactions = 0;" +
"PageTimeout = 5;" +
"MaxScanRows = 8;" +
"MaxBufferSize = 2048;" +
"FIL = MS Access;" +
"DriverId = 25;" +
/ / "DefaultDir = C: \ \ Documents and Settings \ \ Administrator \ \ My Documents;" +
"DBQ = D: \ \ gtk.mdb"
);
int length = 0;
/ /
/ / Set the database connection object
/ /
conctn.setAutoCommit (false);
/ /
/ / Pre-compiler directives
/ /
PreparedStatement pstmt = conctn.prepareStatement ( "insert into testsaveimg (title, image) values (?,?)");
/ /
/ / Get a file input stream
/ /
FileInputStream in = new FileInputStream ( "D: \ \ test.jpg");
length = in.available ();
System.out.println (in.toString () + "has" + length + "bytes");
/ /
/ / Set the value to insert
/ /
pstmt.setString (1, "insert a picture of the title");
pstmt.setBinaryStream (2, in, in.available ());
/ / Here in the file input stream, if would DataInputStream error, in.available () is in the length of
/ /
/ / Insert implementation
/ /
System.out.println ( "inserted" + pstmt.executeUpdate () + "row data");
conctn.commit ();
pstmt.close ();
conctn.close ();
) catch (Exception e) (
e.printStackTrace ();
System.out.println ( "wrong!");

)
)
)



Jsp And Database Articles


Can't Find What You're Looking For?


Rating: Not yet rated

Comments

No comments posted.