初学java 编译无错误 但不出结果 求救
我调了三天 也没找到 郁闷
源代码
package connDB;
import java.sql.*;
public class DatabaseConn
{
private Statement stmt = null ;
private Connection conn = null;
ResultSet rs = null ;
String sql ;
public DatabaseConn ( ) //构造方法
{
}
public void OpenConn ( ) throws Exception //打开数据库的方法
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn = DriverManager.getConnection("jdbc:odbc:stuDB");
}
catch ( Exception e )
{
System.err.println ("数据库连接:" + e.getMessage ( ) ) ;
}
}
public ResultSet excuteQuery ( String sql ) //查询数据的方法
{
stmt = null ;
rs = null ;
try
{
stmt = conn.createStatement ( ResultSet.TYPE_SCROLL_INSENSITIVE ,
ResultSet.CONCUR_READ_ONLY ) ;
rs = stmt.executeQuery ( sql ) ;
}
catch ( SQLException e )
{
System.err.println ( "查询数据:" + e.getMessage ( ) ) ;
}
return rs ;
}
public void executeUpdate ( String sql ) //更新数据的方法
{
stmt = null ;
rs = null ;
try
{
stmt = conn.createStatement ( ResultSet.TYPE_SCROLL_INSENSITIVE ,
ResultSet.CONCUR_READ_ONLY ) ;
stmt.executeQuery ( sql ) ;
conn.commit ( ) ;
}
catch ( SQLException e )
{
System.err.println( "更新数据; " + e.getMessage ( ) );
}
}
public void closeStmt ( ) //释放对象的方法
{
try
{
stmt.close ( );
}
catch ( SQLException e )
{
System.err.println ( "释放对象: " + e.getMessage ( ) );
}
}
public void closeConn ( ) //释放对象的方法
{
try
{
conn.close ( );
}
catch ( SQLException e)
{
System.err.println ( "释放对象: " + e.getMessage ( ) );
}
}
public static String toGBK ( String str) //转换编码的方法
{
try
{
if ( str == null )
{
str = " ";
}
else
{
str = new String ( str.getBytes ("ISO-8859-1"),"GBK");
}
}
catch ( Exception e)
{
System.out.println ( e );
}
return str ;
}
}