I wrote a javabean and test it in main function, I found it cann't work,
the error as following:
java.lang.UnsupportedOperationException
java.sql.Statement sun.jdbc.odbc.JdbcOdbcConnection.createStatement(int, int)
java.sql.ResultSet lyf.mydb.executeQuery(java.lang.String, int)
void lyf.mydb.main(java.lang.String[])
Exception in thread main
and source code:
mydb.java
// Copyright (c) 2000 http://jspbbs.yeah.net
package lyf;
/**
* A Class class.
* <P>
* @author liuyufeng
*/
import java.sql.*;
import java.lang.*;
public class mydb
{
String sDBDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
String sConnStr = "jdbc:odbc:lyfbbs";
Connection conn = null;
ResultSet rs = null;
String Username=null;
String Password=null;
String Password1=null;
String Email=null;
String Homepage=null;
String Signs=null;
public mydb() {
try {
Class.forName(sDBDriver);
}
catch(java.lang.ClassNotFoundException e) {
System.err.println("mydb(): " + e.getMessage());
}
}
public ResultSet executeQuery(String sql) {
rs = null;
try {
conn = DriverManager.getConnection(sConnStr);
Statement stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
}
catch(SQLException ex) {
System.err.println("aq.executeQuery: " + ex.getMessage());
}
return rs;
}
public ResultSet executeQuery(String sql,int flag) {
rs = null;
try {
conn = DriverManager.getConnection(sConnStr);
if(flag==1)
{
Statement stmt =
conn.createStatement(java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,java.sql.ResultSet.CONCUR_READ_ONLY);
//Statement stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
}
}
catch(SQLException ex) {
System.err.println("aq.executeQuery: " + ex.getMessage());
}
return rs;
}
/**
* Inserts a comment into the database from data already set in the bean and returns
a confirmation message.
* @return String
*/
public String insertComment(String sSql) {
// create all the variables I will need.
Statement Stmt = null;
try {
// load the driver
conn = DriverManager.getConnection(sConnStr);
// create the statement
Stmt = conn.createStatement();
// execute the sql
int stmtInt = Stmt.executeUpdate(sSql);
// return which row was affected
return "Inserted row " + stmtInt;
} catch (SQLException E) {
return "SQLException: " + E.getMessage();
} catch (Exception e) {
return "Exception: " + e.toString();
} finally {
// ALWAYS, ALWAYS close the connections to the db
try {
Stmt.close();
conn.close();
} catch (Exception E) {
}
}
}
public static void main(String[] args) {
mydb list = new mydb();
list.executeQuery("select * from board",1);
}
}
刘玉锋
[EMAIL PROTECTED]
http://aspfans.yeah.net <ASP爱好者>
http://jspbbs.yeah.net <JSP爱好者>
http://vbfans.yeah.net <VB爱好者>
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets