120 likes | 212 Vues
This tutorial by Bin Tang provides a step-by-step guide on connecting to Sybase using JDBC in JBuilder. Learn to work from home, upload files, connect to Sybase, and integrate with JBuilder. Detailed instructions and code snippets included.
E N D
A tutorial on CSE305 project Bin Tang (Bin Tang@cs.sunysb.edu)
Outline • Work from home • Jbuilder • Sybase and JDBC. • Jisql. • How to connect Sybase using JDBC. • How to integrate into your Jbuilder…
Work from Home • SSH2 client • upload the files to the transaction lab file server • Copy /com(which contains the JDBC driver) to your home machine and set up (see hint page for details) • Interact with Sybase • Using the gateway applet located at http://www.translab.cs.sunysb.edu/demo/gateway.html
How to connect to Sybase using JDBC • http://www.translab.cs.sunysb.edu/demo/menu.java • JDBCDriver = "com.sybase.jdbc.SybDriver"; URL="jdbc:sybase:Tds:sbntdbm.translab.cs.sunysb.edu:5000"; Proxy = "www.translab.cs.sunysb.edu:8000"; String UserID = ”cse305_ta"; String Password = ”abcdefg"; • prop = new Properties(); prop.put("user", UserID); prop.put("password", Password); prop.put("proxy", Proxy);
JDBC Organization Driver1 Driver Manager Application Driver2 DBMS Driver3
How to connect to Sybase using JDBC • Load JDBC Driver and register it to DriverManager Class c =Class.forName("com.sybase.jdbc.SybDriver"); DriverManager.registerDriver((Driver) c.newInstance()); • Connect to Sybase Con = DriverManager.getConnection(URL, prop); • Create a statement object from the connection object(in doSelect()/doSelect2() ). Statement stmtSelect = Con.createStatement(); • Execute the statement object. • ResultSet result = stmtSelect.executeQuery(sSelectStmt); • doSelect(String sSelectStmt, int cols) -- Select • int row_affected = stmtSelect.executeUpdate(sSelectStmt); • doSelect2(String sSelectStmt, int cols) –Update, Insert
Get the result back Statement stmt = mycncCon.createStatement(); ResultSet result = stmt.executeQuery("SELECT Name, Adress FROM Users WHERE Fine > 5.00“, 2); while(result.next()) { jName.setText(result.getString(1)); jAdress.setText(result.getString(2)); }