<%@page language="java" import="java.sql.*"%> <%@ page contentType="text/html;charset=GBK" %> <%! /* An example to demonstrate how to connect and use the driver with the JDBC 1.22 interface. (This driver requires the JDBC 2.0 interface and a JDK 1.2 or higher)*/ public class ClassicDriver { public void dmain(){ String url = "jdbc:inetdae7:localhost"; // use your hostname and port number here String login = "sa"; // use your login here String password = "mssqladm"; // use your password here
try { DriverManager.setLogStream(System.out); // to create more info // for technical support
Class.forName("com.inet.tds.TdsDriver").newInstance(); //or //new com.inet.tds.TdsDriver(); //set a timeout for login and query DriverManager.setLoginTimeout(10); //open a connection to the database Connection connection = DriverManager.getConnection(url,login,password); //to get the driver version DatabaseMetaData conMD = connection.getMetaData(); System.out.println("Driver Name:\t" + conMD.getDriverName()); System.out.println("Driver Version:\t" + conMD.getDriverVersion()); //select a database connection.setCatalog( "master" ); //create a statement Statement st = connection.createStatement(); //execute a query ResultSet rs = st.executeQuery("SELECT * FROM sysusers"); // read the data and put it to the console while (rs.next()){ for(int j=1; j<=rs.getMetaData().getColumnCount(); j++){ System.out.print( rs.getObject(j)+"\t"); } System.out.println(); } //close the objects st.close(); connection.close(); } catch(Exception e) { e.printStackTrace(); } } } %> <% ClassicDriver db = new ClassicDriver(); db.dmain(); %>
http://jtds.sourceforge.net/
stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
其中type_scroll_sensitive是个关键
<%@ page contentType="text/html;charset=GBK" %>
<%!
/* An example to demonstrate how to connect and use the driver with the JDBC 1.22 interface.
(This driver requires the JDBC 2.0 interface and a JDK 1.2 or higher)*/
public class ClassicDriver
{ public void dmain(){
String url = "jdbc:inetdae7:localhost"; // use your hostname and port number here
String login = "sa"; // use your login here
String password = "mssqladm"; // use your password here
try {
DriverManager.setLogStream(System.out); // to create more info
// for technical support
Class.forName("com.inet.tds.TdsDriver").newInstance();
//or
//new com.inet.tds.TdsDriver();
//set a timeout for login and query
DriverManager.setLoginTimeout(10);
//open a connection to the database
Connection connection = DriverManager.getConnection(url,login,password); //to get the driver version
DatabaseMetaData conMD = connection.getMetaData();
System.out.println("Driver Name:\t" + conMD.getDriverName());
System.out.println("Driver Version:\t" + conMD.getDriverVersion()); //select a database
connection.setCatalog( "master" ); //create a statement
Statement st = connection.createStatement(); //execute a query
ResultSet rs = st.executeQuery("SELECT * FROM sysusers"); // read the data and put it to the console
while (rs.next()){
for(int j=1; j<=rs.getMetaData().getColumnCount(); j++){
System.out.print( rs.getObject(j)+"\t");
}
System.out.println();
}
//close the objects
st.close();
connection.close(); } catch(Exception e) {
e.printStackTrace();
}
}
}
%>
<%
ClassicDriver db = new ClassicDriver();
db.dmain();
%>