java连接mysql数据库的方法
时间:2021-07-01 10:21:17
帮助过:19人阅读
com_jdbc_1;
import java.sql.*;
import javax.sql.*;
public class demon_1 {
/**
* @param args
*/
public static void main(String[] args)
throws Exception {
Connection ct=
null;
PreparedStatement ps=
null;
ResultSet rs=
null;
Class.forName(
"com.mysql.jdbc.Driver");
ct=DriverManager.getConnection(
"jdbc:mysql://localhost:3306/test",
"root",
"toor");
ps=ct.prepareStatement(
"select * from testuser");
rs=ps.executeQuery();
int i=
0;
while(rs.next()){
System.out.println(rs.getInt(
1)+
" "+rs.getString(
"username"));
}
}
}
java连接mysql数据库的方法
标签:java mysql