读取mysql中的中文数据问题 jdbc:mysql://localhost/user=root&password=&useUnicode=true&characterEncoding=8859_1这样看看能不能连 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 不行……一个类型的错误,只是变为java.sql.SQLException: General error: Incorrect database name '?user=root&password=&useUnicode=true&characterEncoding=8859_1' getConnection("jdbc:mysql://localhost/?useUnicode=true&characterEncoding=8859_1","root","")这样呢?很奇怪啊,我这边都可以哦 java.sql.SQLException: General error: Unknown database 'mysql?useUnicode=true&characterEncoding=8859_1'还是这个……郁闷PS:我用的是Apache Tomcat/4.1.18 不加上mysql这个数据表名还会是这样? 对,加不加都会报错只有getConnection("jdbc:mysql://localhost/mysql","root","")才能连接上 mysql 的数据库经常出中文问题! 怎么可能加不加都是报mysql表的错????重启服务器试试看? 可是我同时写的PHP脚本却可以正常访问,并显示中文 源代码:import java.sql.*;public class db2{ static public void main(String args[]) { Connection conn = null; Statement s = null; ResultSet rs = null; try { System.out.println("Loading JDBC driver ....."); DriverManager.registerDriver(new org.gjt.mm.mysql.Driver()); System.out.println("Loaded."); try { System.out.println("\nConnecting to MySQL ......"); conn = DriverManager.getConnection("jdbc:mysql://localhost/mysql?useUnicode=true&characterEncoding=8859_1","root",""); System.out.println("Connected."); try { System.out.println("\nCreating statement......"); s = conn.createStatement(); System.out.println("Created."); try { System.out.println("\nCreating resultset......"); rs = s.executeQuery("select * from user"); System.out.println("Created."); while (rs.next()) { System.out.println("\n " + rs.getString(2)); } }catch (Exception exce) { System.out.println("Failed."); exce.printStackTrace(); } }catch (Exception exc) { System.out.println("Failed."); exc.printStackTrace(); } }catch (Exception ex) { System.out.println("Failed !"); ex.printStackTrace(); } }catch (Exception e) { System.out.println("Failed ."); e.printStackTrace(); } finally { if (conn != null) { if (s != null) { if (rs != null) { try { System.out.println("\nClosing resultset......"); rs.close(); System.out.println("Closed."); }catch (Exception eR) { System.out.println("Failed."); } } try { System.out.println("\nClosing statement......"); s.close(); System.out.println("Closed."); }catch (Exception eS) { System.out.println("Failed."); } } try { System.out.println("\nClosing connection ....."); conn.close(); System.out.println("Closed."); }catch (Exception exception) { System.out.println("Failed !"); exception.printStackTrace(); } } } }};try语句太多:) 关于httpClient poi3.6中文乱码 找不到解决办法 两个不同页面之间的HMTL组件如何交互? area 为什么jsp有时候会显示空白页? 这个算法如何实现呢。关于请假的时间算法问题,请教各位。分数只有10分了啊。抱歉。 图形化Web开发框架WebPage3 在线等马上结:关于登录问题 请用过BeanBox的朋友进来看看 红封面的jsp编程大全怎么样? j2ee要什么配置啊 关于在JSP页面对数据进行排序的问题--谢谢
一个类型的错误,只是变为
java.sql.SQLException: General error: Incorrect database name '?user=root&password=&useUnicode=true&characterEncoding=8859_1'
","root","")这样呢?很奇怪啊,我这边都可以哦
郁闷PS:我用的是Apache Tomcat/4.1.18
只有getConnection("jdbc:mysql://localhost/mysql","root","")才能连接上
重启服务器试试看?
import java.sql.*;public class db2
{
static public void main(String args[])
{
Connection conn = null;
Statement s = null;
ResultSet rs = null;
try
{
System.out.println("Loading JDBC driver .....");
DriverManager.registerDriver(new org.gjt.mm.mysql.Driver());
System.out.println("Loaded.");
try
{
System.out.println("\nConnecting to MySQL ......");
conn = DriverManager.getConnection("jdbc:mysql://localhost/mysql?useUnicode=true&characterEncoding=8859_1","root","");
System.out.println("Connected."); try
{
System.out.println("\nCreating statement......");
s = conn.createStatement();
System.out.println("Created.");
try
{
System.out.println("\nCreating resultset......");
rs = s.executeQuery("select * from user");
System.out.println("Created.");
while (rs.next())
{
System.out.println("\n " + rs.getString(2));
}
}catch (Exception exce)
{
System.out.println("Failed.");
exce.printStackTrace();
}
}catch (Exception exc)
{
System.out.println("Failed.");
exc.printStackTrace();
}
}catch (Exception ex)
{
System.out.println("Failed !");
ex.printStackTrace();
}
}catch (Exception e)
{
System.out.println("Failed .");
e.printStackTrace();
}
finally
{
if (conn != null)
{
if (s != null)
{
if (rs != null)
{
try
{
System.out.println("\nClosing resultset......");
rs.close();
System.out.println("Closed.");
}catch (Exception eR)
{
System.out.println("Failed.");
}
}
try
{
System.out.println("\nClosing statement......");
s.close();
System.out.println("Closed.");
}catch (Exception eS)
{
System.out.println("Failed.");
}
}
try
{
System.out.println("\nClosing connection .....");
conn.close();
System.out.println("Closed.");
}catch (Exception exception)
{
System.out.println("Failed !");
exception.printStackTrace();
}
}
}
}
};try语句太多:)