添加Mysql jdbc驱动自不必说,数据库连接类Connection,操作数据库的句柄类Statement,
创建连接对象
Connection con = null;
Statement stmt = null;
连接mysql数据库
String url = "jdbc:mysql://localhost:3306/javaTest";//mysql数据库url
String driver = "com.mysql.jdbc.Driver";//驱动名称
try{
Class.forName(driver);//加载及注册JDBC驱动程序
con = (Connection) DriverManager.getConnection(url,"root","root");//连接数据库
stmt = (Statement) con.createStatement();
}
catch(Exception e)
{
System.out.println("错啦");
}
执行sql语句:
ResultSet rs = null;
rs = stmt.executeQuery(strSQL);
rs.next();