package jdbcdemo; import java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.Statement;public class jdbcdemo {private static final String url = "jdbc:mysql://127.0.0.1:3306/demo?useUnicode=true&characterEncoding=utf-8";private static final String user = "root";private static final String password = "doce";public static void main(String[] args) throws Exception {//1、加载mysql驱动Class.forName("com.mysql.jdbc.Driver"); //2、获得数据库连接Connection connection=DriverManager.getConnection(url ,user , password);//3、通过连接操作数据库,实现增删改查Statement statement=connection.createStatement();//4、执行sql语句ResultSet re = statement.executeQuery("select user_name,age from imooc_goddess;");while(re.next()){ System.out.println(re.getString("user_name")+","+re.getInt("age"));}}}
1 回答
已采纳
AScorpio
TA贡献18条经验 获得超10个赞
java不是很清楚,我在php中会用mysql_query("set names utf8"); //告诉数据库,发送和接受数据用utf8;
试试看,在java中执行下,set names utf8 这句SQL语句
添加回答
举报
0/150
提交
取消