jdbc驱动到官网下载,放在jdk的相关目录下面,或者jar文件加入到工程下面 package test_mysql;import java.sql.*;import java.util.Set;public class testjdbc {public static Connection getConnection() throws ClassNotFoundException, SQLException{Stri
jdbc驱动到官网下载,放在jdk的相关目录下面,或者jar文件加入到工程下面
package test_mysql;
import java.sql.*;
import java.util.Set;
public class testjdbc {
public static Connection getConnection() throws ClassNotFoundException, SQLException{
String URL="jdbc:mysql://localhost:3306/employees";
//加载驱动程序
Class.forName("com.mysql.jdbc.Driver");
String user="root";
String passwd="";
//默认密码为空
//还有选择数据库,哪个数据
//DriverManager.
//Connection con=DriverManager.getConnection(URL, user, passwd);
//Connection con=DriverManager.getConnection(url, user, password);
String test_url="";
//String my_url="jdbc:mysql://localhost:3306;DatabaseName=employees;User=root;Password=";
//test_url+=URL+3306+";"+"DatabaseName=employees;"+"User=root;"+"Password="+"";
Connection con=DriverManager.getConnection(URL,user,passwd);
return con;
}
public static void main(String[] args){
String sql="select * from departments";
Statement statement=null;
Connection con=null;
ResultSet set=null;
try {
con = getConnection();
//con.set
if(con==null)
System.out.println("con null");
statement=con.createStatement();
set=statement.executeQuery(sql);
//int n=set.getFetchSize();
//System.out.println(n);
while(set.next()){
System.out.println(set.getString(1)+" "+set.getString(2));
}
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
if(con!=null)
try {
set.close();
statement.close();
con.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}更多相关教程请访问 MySQL视频教程
启科网络商城系统由启科网络技术开发团队完全自主开发,使用国内最流行高效的PHP程序语言,并用小巧的MySql作为数据库服务器,并且使用Smarty引擎来分离网站程序与前端设计代码,让建立的网站可以自由制作个性化的页面。 系统使用标签作为数据调用格式,网站前台开发人员只要简单学习系统标签功能和使用方法,将标签设置在制作的HTML模板中进行对网站数据、内容、信息等的调用,即可建设出美观、个性的网站。
0
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号