|
调了好久,前几天也在论坛中请教过,不过还是没有解决问题!还请各位帮忙看看!
附的图片是调试出错的报告!user和password都是正确的!
import java.sql.*;
import java.io.*;
import java.util.*;
import java.lang.*;
/**
This program tests that the database--MySQL and the JDBC
driver are correctly configured.
*/
class TestDB2
{
public static void main (String args[])
{
try
{
try{ Class.forName("com.mysql.jdbc.Driver").newInstance();}
catch(Exception e){}
String url = "jdbc:mysql://WQCH/test?user=root&password=12345678";
Connection conn = DriverManager.getConnection(url);
Statement stat = conn.createStatement();
stat.execute("CREATE TABLE Greetings (Name CHAR(20))");
stat.execute(
"INSERT INTO Greetings VALUES ('Hello, World!')");
ResultSet result
= stat.executeQuery("SELECT * FROM Greetings");
result.next();
System.out.println(result.getString(1));
result.close();
//stat.execute("DROP TABLE Greetings");
stat.close();
conn.close();
}
catch (SQLException ex)
{
while (ex != null)
{
ex.printStackTrace();
ex = ex.getNextException();
}
}
catch (Exception ex)
{
ex.printStackTrace();
}
}
} |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
|