package ;
import ;
import;
import;
import;
publicclass DBUtil {
//创建三个常量来存放地址、用户名、和密码 ctrl +shift+x 变为大写
privatestaticfinal String URL="jdbc:mysql://127.0.0.1:3306/imooc";
privatestaticfinal String NAME="root";
privatestaticfinal String PASSWORD="5220";
//这里我们首先抛出一个异常
publicstaticvoid main(String[] args) throws Exception {
//1.加载驱动程序
Class.forName("");
//2.获取数据库的连接 (数据库的地址、用户名 、密码来连接我们的数据库)
Connectionconn=DriverManager.getConnection(URL, NAME, PASSWORD);
//3.通过数据库的连接操作数据库,实现增删改查
stmt =conn.createStatement();
ResultSetrs=stmt.executeQuery("selectuser_name,age from imooc_goddess");
while(rs.next()) {
System.out.println(rs.getString("user_name")+","+rs.getInt("age"));
}
}
}
相关文章
- (JAVA项目)连接数据库 报错Exception in thread "main" : .
- 【Java】BigDecimal中的divide方法报错,Exception in thread "main" java.lang.ArithmeticException:
- 成功解决Java 报错: Exception in thread "main" java.util.InputMismatchException
- 报错:Exception in thread "main" java.lang.NoClassDefFoundError: Lorg/apache/hadoop/fs/FileSystem
- spark-shell报错:Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/hadoop/fs/FSDataInputStream
- (Unknown Source)">Spring报错:Exception in thread "main" java.lang.IllegalArgumentException at org.springframework.asm.ClassReader.
(Unknown Source) - 解决Exception in thread "main" java.nio.BufferOverflowException报错
- json 测试报错:Exception in thread "main" java.lang.NoClassDefFoundError
- 一个环境变量导致运行报错Exception in thread "main" java.lang.NoClassDefFoundError:
- javamail开发报错Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/mail/util