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驅(qū)動(dòng)Class.forName("com.mysql.jdbc.Driver");??//2、獲得數(shù)據(jù)庫(kù)連接Connection connection=DriverManager.getConnection(url ,user , password);//3、通過連接操作數(shù)據(jù)庫(kù),實(shí)現(xiàn)增刪改查Statement statement=connection.createStatement();//4、執(zhí)行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"));}}}
mysql鏈接時(shí)出現(xiàn)亂碼,該如何指定全部的編碼方式呢
qq_微笑王子_0
2017-02-27 10:19:09