package com.test.tool;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class JDBCUtlTool {
public static Connection getConnection(){
String driver="com.mysql.jdbc.Driver"; //获取mysql数据库的驱动类
String url="jdbc:mysql://localhost:3306/test"; //连接数据库(kucun是数据库名)
String name="root";//连接mysql的用户名
String pwd="123456";//连接mysql的密码
try{
Class.forName(driver);
Connection conn=DriverManager.getConnection(url,name,pwd);//获取连接对象
return conn;
}catch(ClassNotFoundException e){
e.printStackTrace();
return null;
}catch(SQLException e){
e.printStackTrace();
return null;
}
}
public static void closeAll(Connection conn,PreparedStatement ps,ResultSet rs){
try{
if(rs!=null){
rs.close();
}
}catch(SQLException e){
e.printStackTrace();
}
try{
if(ps!=null){
ps.close();
}
}catch(SQLException e){
e.printStackTrace();
}
try{
if(conn!=null){
conn.close();
}
}catch(SQLException e){
e.printStackTrace();
}
}
public static void main(String[] args) throws SQLException
{
Connection cc=JDBCUtlTool.getConnection();
if(!cc.isClosed())
System.out.println("Succeeded connecting to the Database!");
Statement statement = cc.createStatement();
String sql = "select * from test2";
ResultSet rs = statement.executeQuery(sql);
while(rs.next()) {
System.out.println(rs.getString("id")+"");
}
}
}
疯狂医院达什医生中文版(Crazy Hospital)
疯狂医院达什医生最新版是一款医院模拟经营类游戏,逼真的场景画
宝宝庄园官方版
宝宝庄园官方版是一款超级经典好玩的模拟经营类型的手游,这个游
桃源记官方正版
桃源记是一款休闲娱乐类的水墨手绘风格打造的模拟经营手游。玩家
长途巴士模拟器手机版
长途巴士模拟器汉化版是一款十分比真好玩的大巴车模拟驾驶运营类
房东模拟器最新版2024
房东模拟器中文版是一个超级有趣的模拟经营类型的手游,这个游戏