package jdbc;
import java.awt.GradientPaint;
import java.sql.*;
public class conn {
static Connection con;
static Statement sql;
static ResultSet res;
public Connection getConnection(){
try {
Class.forName("com.mysql.jdbc.Driver");
Connection conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/db_hotel","root","123456");
System.out.println(conn);
} catch (ClassNotFoundException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
} catch (SQLException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
return con;
}
public static void main(String[] args) {
conn c = new conn();
con = c.getConnection();
try {
sql = con.createStatement(); //空指针异常
res = sql.executeQuery("select*from tb_room");
while(res.next()){
String id = res.getString("id");
String room = res.getString("room");
String price = res.getString("price");
String information = res.getString("information");
System.out.println("id");
System.out.println("room");
System.out.println("price");
System.out.println("information");
}
} catch (SQLException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
}
}
堂堂堂堂糖糖糖童鞋
Margaret_
ing
慕的地6079101
puguole
ing
ing
ing
ing
慕粉0958184631
相关分类