mysql连接数据库
来源:互联网 发布:广东十一选五遗漏数据 编辑:程序博客网 时间:2024/06/06 04:00
package com.hkd.test;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import com.mysql.jdbc.Statement;
public class test {
public static void main(String[] args) {
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
System.out.println("创建失败");
e.printStackTrace();
}
try {
Connection conn =DriverManager.getConnection("jdbc:mysql://localhost:3306/school", "root", "root");
java.sql.Statement sta =conn.createStatement();
//int a =sta.executeUpdate("insert into school values(null,'大侠',16,null)");
//if(a>0){
//System.out.println("成功");
//}else{
// System.out.println("失败");
//}
String sql ="select * from school";
ResultSet rs = sta.executeQuery(sql);
while(rs.next()){
System.out.println(rs.getInt("studentno"));
System.out.println(rs.getString("name"));
System.out.println(rs.getInt("age"));
System.out.println(rs.getInt("tel"));
}
rs.close();
sta.close();
conn.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import com.mysql.jdbc.Statement;
public class test {
public static void main(String[] args) {
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
System.out.println("创建失败");
e.printStackTrace();
}
try {
Connection conn =DriverManager.getConnection("jdbc:mysql://localhost:3306/school", "root", "root");
java.sql.Statement sta =conn.createStatement();
//int a =sta.executeUpdate("insert into school values(null,'大侠',16,null)");
//if(a>0){
//System.out.println("成功");
//}else{
// System.out.println("失败");
//}
String sql ="select * from school";
ResultSet rs = sta.executeQuery(sql);
while(rs.next()){
System.out.println(rs.getInt("studentno"));
System.out.println(rs.getString("name"));
System.out.println(rs.getInt("age"));
System.out.println(rs.getInt("tel"));
}
rs.close();
sta.close();
conn.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
阅读全文
0 0
- 连接池连接Mysql数据库
- JDBC连接MySQL数据库
- JDBC连接MySQL数据库
- JSP连接Mysql数据库
- java连接MySql数据库!
- jsp连接数据库---Mysql
- JSP 连接MYSQL数据库
- jsp 连接 mysql 数据库
- JAVA 连接 MySQL 数据库
- JSP连接MySQL数据库
- JSP连接Mysql数据库
- JSP连接Mysql数据库
- Jsp连接Mysql数据库
- JSP连接mysql数据库
- PHP连接MYSQL数据库
- mysql连接数据库
- JSP连接mysql数据库
- VC++连接MySQL数据库
- UTF-8和GBK有什么区别
- java-对象的引用、对象的比较
- 将字符串中的单词翻转,不能使用php提供的任何函数 strlen 除外
- 数据精度
- MapReduce任务运行到running job卡住
- mysql连接数据库
- Leetcode58. Length of Last Word
- 上位机+三菱PLC+TCP+SLMP
- 括号匹配检测(难度:半颗星)
- sqlserver连接数据库
- Android:打造一个属于自己的浏览器(2)
- 什么时候使用字节流、什么时候使用字符流,二者的区别
- Unix、Posix和标准UniX规范
- 自定义View练习