import java.lang.reflect.Array;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import com.mysql.jdbc.Connection;
import com.mysql.jdbc.Statement;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import com.mysql.jdbc.Connection;
import com.mysql.jdbc.Statement;
public class t {
public static void main(String args[]) throws ClassNotFoundException, SQLException{
Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://localhost:3306/javaweb?user=root&password=080302&useUnicode=true&characterEncoding=gbk";
Connection conn= (Connection) DriverManager.getConnection(url);
Statement ps=(Statement) conn.createStatement();
String sql="select * from user";
ResultSet rs=ps.executeQuery(sql);
System.out.println(rs);
if(rs.next()){//只显示一行
System.out.println(rs.getString(3));//从1开始
}
ResultSet rs1=ps.executeQuery(sql);
while(rs1.next()){//显示所有行相关信息
System.out.println(rs1.getString(2));
}
}
}
public static void main(String args[]) throws ClassNotFoundException, SQLException{
Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://localhost:3306/javaweb?user=root&password=080302&useUnicode=true&characterEncoding=gbk";
Connection conn= (Connection) DriverManager.getConnection(url);
Statement ps=(Statement) conn.createStatement();
String sql="select * from user";
ResultSet rs=ps.executeQuery(sql);
System.out.println(rs);
if(rs.next()){//只显示一行
System.out.println(rs.getString(3));//从1开始
}
ResultSet rs1=ps.executeQuery(sql);
while(rs1.next()){//显示所有行相关信息
System.out.println(rs1.getString(2));
}
}
}
转载于:https://blog.51cto.com/hiperfect/948962