jdbc登陆查询(待更新)
时间:2021-07-01 10:21:17
帮助过:2人阅读
slect;
import java.sql.*
;
public class Select {
public static void main(String[] args){
String url = "jdbc:mysql://localhost:3306/大吉大利"
;
String user = "root"
;
String password = "123456"
;
try {
Class.forName("com.mysql.jdbc.Driver"
);
Connection conn =
DriverManager.getConnection(url, user, password);
if(!
conn.isClosed())
System.out.println("登陆成功"
);
Statement statement =
conn.createStatement();
String sql = "select * from persion"
;
ResultSet rs =
statement.executeQuery(sql);
while(rs.next()) {
String id=rs.getString(1
);
String name=rs.getString(2
);
System.out.println(id+
name);
}
rs.close();
conn.close();
} catch(Exception e) {
e.printStackTrace();
}
}
}
jdbc登陆查询(待更新)
标签:string query state nbsp exce word pass select jar