还有点问题这个是调好的
import java.sql.*; public class jdbcyouhuo1 { public String[] getUserName(String connString, String SQLString) throws SQLException { Connection connection = DriverManager.getConnection(connString,"root", "root"); try { Statement statement = connection.createStatement(); ResultSet rs = statement.executeQuery(SQLString); int rowcount = 0; int i = 0; if( rs.last()) { rowcount = rs.getRow(); rs.beforeFirst(); } String[] retArray = new String[rowcount]; while (rs.next()) { retArray[i++] = rs.getString("user_name"); } statement.close(); return retArray; } catch (SQLException e ) { System.err.print("SQLException: "); } finally { } return null; } } 这个是还有问题的一半import java.sql.*;public class jdbcyouhua2 { public static void main(String[] agrs){ String connString = "jdbc:mysql://localhost/ace?useUnicode=true&characterEncoding=utf-8"; String SQLString = "SELECT user_name FROM users"; jdbcyouhuo1 jb1 = new jdbcyouhuo1(); try{ String[] rs = jb1.getUserName(connString, SQLString); //while(rs.next()){ System.out.println(rs.getString("user_name")); } } catch(Exception e) { e.printStackTrace(); } finally { } } }
是输出那里还有问题
Cannot invoke getString(String) on the array type String[]
HUX布斯
相关分类