📄 sample.java
字号:
import java.sql.*;
/**
* Test retrieving values back using scrollable updatable resultSet.
*
*/
public class sample
{
static public void main(String args[])
throws java.lang.ClassNotFoundException, Exception
{
Connection cx = null;
try {
Class.forName("com.ashna.jturbo.driver.Driver");
String url = "jdbc:JTurbo://localhost:1433/pubs/sql70=true";
String user = "sa";
String password = "";
//DriverManager.setLogStream(System.out);
// open the database connection
cx = java.sql.DriverManager.getConnection(url, user, password);
}
catch(Exception e) {
System.out.println(e);
}
System.out.println("Test all the SQLServer ScrollableResultset");
boolean passed = true;
int count = 0;
Statement stmt = null;
stmt = cx.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
ResultSet rs;
try
{
stmt.executeUpdate("drop table sample");
}
catch (Exception e)
{
}
String sql = "create table sample (val varchar(10) null)";
count = stmt.executeUpdate(sql);
System.out.println("Created Table 'sample' in the pubs database");
cx.setAutoCommit(false);
for(int i=1;i<40;i++) {
// Insert a row via a Statement
sql =
"insert into sample " +
" (val)" +
" values " +
" ('"+i+"')";
count = stmt.executeUpdate(sql);
}
System.out.println("Inserted 40 rows into the 'sample' table");
//stmt = cx.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
rs = stmt.executeQuery("select * from sample");
rs.first();
System.out.println("FIRST ROW NUM: "+rs.getRow());
// System.out.println("Is First? "+rs.isFirst());
rs.last();
System.out.println("LAST ROW NUM: "+rs.getRow());
// System.out.println("Is Last? "+rs.isLast());
rs.beforeFirst();
System.out.println("BEFORE FIRST ROW NUM: "+rs.getRow());
// System.out.println("Is Before First? "+rs.isBeforeFirst());
while (rs.next()) {
System.out.println("NEXT ROW NUM: "+rs.getRow());
//System.out.println("Going forward: "+rs.getString(1));
}
rs.afterLast();
System.out.println("AFTER LAST ROW NUM: "+rs.getRow());
// System.out.println("Is After Last? "+rs.isAfterLast());
while(rs.previous()) {
System.out.println("PREVIOUS ROW NUM: "+rs.getRow());
// System.out.println("Going back: "+rs.getString(1));
}
rs.first();
System.out.println("FIRST ROW NUM: "+rs.getRow());
// System.out.println("Is First? "+rs.isFirst());
while (rs.next()) {
System.out.println("NEXT ROW NUM: "+rs.getRow());
// System.out.println("Going forward: "+rs.getString(1));
}
rs.last();
System.out.println("LAST ROW NUM: "+rs.getRow());
//System.out.println("Is Last? "+rs.isLast());
while (rs.previous()) {
System.out.println("PREVIOUS ROW NUM: "+rs.getRow());
//System.out.println("Going forward: "+rs.getString(1));
}
rs.close();
stmt.executeUpdate("drop table sample");
System.out.println("Dropping the table 'sample' from pubs database");
stmt.close();
cx.close();
System.out.println("Test Completed!");
System.exit(-1);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -