代码:
import java.sql.*;
public class conn
{
public static void main(String arg[])
{
try
{
Class.forName( "org.gjt.mm.mysql.Driver ");
Connection con=DriverManager.getConnection( "jdbc:mysql://127.0.0.1:3306/first1 ", "root ", " ");
Statement stmt = con.createStatement();
String sql = "SELECT * FROM first2 ";
ResultSet rs = stmt.executeQuery( sql );
String rs1;
while(rs.next())
{
for(int i=1;i <=3;i++)
{
rs1 = rs.getString(i);
System.out.print(rs1 + "\t ");
}
System.out.println();
}
rs.close();
stmt.close();
con.close();
}catch(ClassNotFoundException e)
{
System.out.println( "错误: " + e);
}
catch(SQLException e)
{
System.out.println( "错误: " + e);
}
}
}
结果:
F:\code\java\mysql> java conn
1 ? ??
2 ?? ????
3 ?? ????
------解决方案--------------------
Connection con=DriverManager.getConnection( "jdbc:mysql://127.0.0.1:3306/first1 ", "root ", " ");这后面好像还要加点东西的好像是什么
好像是说加个什么编码格式什么什么的
------解决方案--------------------
试试
jdbc:mysql://127.0.0.1:3306/first1?useUnicode=true&characterEncoding=GBK