java向mysql中插入中文出现乱码的问题
我的代码如下,如何修改才能够让Java传入Mysql的语句不出现乱码?
我的Mysql里的my.ini已经设为了gbk了另外,这段代码如何写才可以不通过读取文件连接数据库?
我改了很多次了,都会报错public static Connection getConnection()
throws SQLException, IOException
{
Properties props = new Properties();
FileInputStream in
= new FileInputStream("database.properties");
props.load(in);
in.close(); String drivers = props.getProperty("jdbc.drivers");
if (drivers != null)
System.setProperty("jdbc.drivers", drivers);
String url = props.getProperty("jdbc.url");
String username = props.getProperty("jdbc.username");
String password = props.getProperty("jdbc.password"); return
DriverManager.getConnection(url, username, password);
}
我的代码如下,如何修改才能够让Java传入Mysql的语句不出现乱码?
我的Mysql里的my.ini已经设为了gbk了另外,这段代码如何写才可以不通过读取文件连接数据库?
我改了很多次了,都会报错public static Connection getConnection()
throws SQLException, IOException
{
Properties props = new Properties();
FileInputStream in
= new FileInputStream("database.properties");
props.load(in);
in.close(); String drivers = props.getProperty("jdbc.drivers");
if (drivers != null)
System.setProperty("jdbc.drivers", drivers);
String url = props.getProperty("jdbc.url");
String username = props.getProperty("jdbc.username");
String password = props.getProperty("jdbc.password"); return
DriverManager.getConnection(url, username, password);
}
http://www.kecourser.com/download/installsupport/mysqldatabase.htm
问题是我通过JAVA代码中插入中文就显示不出来
我连接数据库的文件:jdbc.drivers=org.gjt.mm.mysql.Driver
jdbc.url=jdbc:mysql://localhost:3306/library
jdbc.username=root
jdbc.password=1234567连接代码在楼顶