//表已经建好了。
//conn = DriverManager.getConnection(url,user,passwordofDB); 这句总是出现Connection不能转换为Connection。
//望高手指点,谢谢!
import java.sql.*;
import com.mysql.jdbc.Connection;
import com.mysql.jdbc.ResultSet;
import com.mysql.jdbc.*;
import com.mysql.jdbc.Statement;
import com.mysql.jdbc.jdbc2.optional.MysqlXid;
public class JdbcDome {
public static void main(String[] args) {
try{
// Class.forName("org.git.mm.mysql.Driver");
// java.sql.DriverManager.registerDriver(new org.git.mm.mysql.Driver());
Class.forName("com.mysql.jdbc.Driver");
}
catch(java.lang.ClassNotFoundException e)
{
System.out.println("Class Not Found Exception occur.Message is:");
System.out.println(e.getMessage());
}
try{
Statement stmt;
ResultSet rs;
String url="jdbc:mysql://localhost;8080/test";
String user= "root";
String passwordofDB= "kaka19860205";
Connection conn=null;
try{
conn = DriverManager.getConnection(url,user,passwordofDB);
}
catch(Exception e)
{
e.printStackTrace();
}
stmt=(Statement) conn.createStatement();
rs=(ResultSet) stmt.executeQuery("select *from userinfo");
while(rs.next())
{
int id=rs.getInt(1);
String name=rs.getString(2);
String password=rs.getString(3);
int age=rs.getInt(4);
String gender=rs.getString(5);
String email=rs.getString(6);
System.out.println("id"+id);
System.out.println("name"+name);
System.out.println("password"+password);
System.out.println("age"+age);
System.out.println("gender"+gender);
System.out.println("email"+email);
}
rs.close();
stmt.close();
conn.close();
catch(SQLException e)
{
System.out.println("Class Not Found Exception occur.Message is:");
System.out.println(e.getMessage());
}
}
php怎么获取js值
菜鸟跪求,sqoop数据导出不完整是什么问题
php错误提示: mysql_fetch_row(): supplied argument is not a valid MySQL
求助啊(某双窗体程序编写)
各位大哥大姐帮忙看下这是怎么回事~
超链接如何调用js里的网址
SQL server2008 java jdbc 链接问题 网上很多方法都试了大家来看下谢谢了
import com.mysql.jdbc.Connection;
import com.mysql.jdbc.ResultSet;
import com.mysql.jdbc.*;
import com.mysql.jdbc.Statement;
全部改成
java.sql.* 就行了
com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception:
** BEGIN NESTED EXCEPTION **
java.net.UnknownHostException
MESSAGE: localhost;8080
STACKTRACE:
java.net.UnknownHostException: localhost;8080
at java.net.Inet4AddressImpl.lookupAllHostAddr(Native Method)
at java.net.InetAddress$1.lookupAllHostAddr(InetAddress.java:849)
at java.net.InetAddress.getAddressFromNameService(InetAddress.java:1200)
at java.net.InetAddress.getAllByName0(InetAddress.java:1153)
at java.net.InetAddress.getAllByName(InetAddress.java:1083)
at java.net.InetAddress.getAllByName(InetAddress.java:1019)
at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:246)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:271)
at com.mysql.jdbc.Connection.createNewIO(Connection.java:2744)
at com.mysql.jdbc.Connection.<init>(Connection.java:1553)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:285)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at JdbcDome.main(JdbcDome.java:30)
** END NESTED EXCEPTION **
Last packet sent to the server was 0 ms ago.
at com.mysql.jdbc.Connection.createNewIO(Connection.java:2820)
at com.mysql.jdbc.Connection.<init>(Connection.java:1553)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:285)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at JdbcDome.main(JdbcDome.java:30)
Exception in thread "main" java.lang.NullPointerException
at JdbcDome.main(JdbcDome.java:39)
com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception:
** BEGIN NESTED EXCEPTION **
java.net.UnknownHostException
MESSAGE: localhost;8080
STACKTRACE:
java.net.UnknownHostException: localhost;8080
at java.net.Inet4AddressImpl.lookupAllHostAddr(Native Method)
at java.net.InetAddress$1.lookupAllHostAddr(InetAddress.java:849)
at java.net.InetAddress.getAddressFromNameService(InetAddress.java:1200)
at java.net.InetAddress.getAllByName0(InetAddress.java:1153)
at java.net.InetAddress.getAllByName(InetAddress.java:1083)
at java.net.InetAddress.getAllByName(InetAddress.java:1019)
at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:246)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:271)
at com.mysql.jdbc.Connection.createNewIO(Connection.java:2744)
at com.mysql.jdbc.Connection.<init>(Connection.java:1553)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:285)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at JdbcDome.main(JdbcDome.java:30)
** END NESTED EXCEPTION **
Last packet sent to the server was 0 ms ago.
at com.mysql.jdbc.Connection.createNewIO(Connection.java:2820)
at com.mysql.jdbc.Connection.<init>(Connection.java:1553)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:285)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at JdbcDome.main(JdbcDome.java:30)
Exception in thread "main" java.lang.NullPointerException
at JdbcDome.main(JdbcDome.java:39)
错误代码::::
com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception:
** BEGIN NESTED EXCEPTION **
com.mysql.jdbc.CommunicationsException
MESSAGE: Communications link failure due to underlying exception:
** BEGIN NESTED EXCEPTION **
java.io.EOFException
MESSAGE: Can not read response from server. Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost.
STACKTRACE:
java.io.EOFException: Can not read response from server. Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost.
at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:1997)
at com.mysql.jdbc.MysqlIO.readPacket(MysqlIO.java:573)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1044)
at com.mysql.jdbc.Connection.createNewIO(Connection.java:2748)
at com.mysql.jdbc.Connection.<init>(Connection.java:1553)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:285)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at JdbcDome.main(JdbcDome.java:30)
** END NESTED EXCEPTION **
Last packet sent to the server was 0 ms ago.
STACKTRACE:
com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception:
** BEGIN NESTED EXCEPTION **
java.io.EOFException
MESSAGE: Can not read response from server. Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost.
STACKTRACE:
java.io.EOFException: Can not read response from server. Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost.
at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:1997)
at com.mysql.jdbc.MysqlIO.readPacket(MysqlIO.java:573)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1044)
at com.mysql.jdbc.Connection.createNewIO(Connection.java:2748)
at com.mysql.jdbc.Connection.<init>(Connection.java:1553)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:285)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at JdbcDome.main(JdbcDome.java:30)
** END NESTED EXCEPTION **
Last packet sent to the server was 0 ms ago.
at com.mysql.jdbc.MysqlIO.readPacket(MysqlIO.java:641)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1044)
at com.mysql.jdbc.Connection.createNewIO(Connection.java:2748)
at com.mysql.jdbc.Connection.<init>(Connection.java:1553)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:285)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at JdbcDome.main(JdbcDome.java:30)
** END NESTED EXCEPTION **
Last packet sent to the server was 0 ms ago.
at com.mysql.jdbc.Connection.createNewIO(Connection.java:2820)
at com.mysql.jdbc.Connection.<init>(Connection.java:1553)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:285)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at JdbcDome.main(JdbcDome.java:30)
Exception in thread "main" java.lang.NullPointerException
at JdbcDome.main(JdbcDome.java:39)
*/
import java.sql.*;
public class JdbcDome {
public static void main(String[] args) {
try{
// Class.forName("org.git.mm.mysql.Driver");
// java.sql.DriverManager.registerDriver(new org.git.mm.mysql.Driver());
Class.forName("com.mysql.jdbc.Driver");
}
catch(java.lang.ClassNotFoundException e)
{
System.out.println("Class Not Found Exception occur.Message is:");
System.out.println(e.getMessage());
}
try{
Statement stmt;
ResultSet rs;
String url="jdbc:mysql://localhost:8080/test";
String user= "root";
String passwordofDB= "kaka19860205";
Connection conn=null;
try{
conn = DriverManager.getConnection(url,user,passwordofDB);
}
catch(Exception e)
{
e.printStackTrace();
}
stmt=(Statement) conn.createStatement();
rs=(ResultSet) stmt.executeQuery("select *from userinfo");
while(rs.next())
{
int id=rs.getInt(1);
String name=rs.getString(2);
String password=rs.getString(3);
int age=rs.getInt(4);
String gender=rs.getString(5);
String email=rs.getString(6);
System.out.println("id"+id);
System.out.println("name"+name);
System.out.println("password"+password);
System.out.println("age"+age);
System.out.println("gender"+gender);
System.out.println("email"+email);
}
rs.close();
stmt.close();
conn.close();
}
catch(SQLException e)
{
System.out.println("Class Not Found Exception occur.Message is:");
System.out.println(e.getMessage());
}
}
}
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class Test {
public static void main(String[] args) {
Connection con = null;
PreparedStatement ps = null;
ResultSet rs = null;
try {
con = ConnectionFactory.getConnection();
String sql = "SELECT id, name, password, age, gender, email " +
"FROM userinfo";
ps = con.prepareStatement(sql);
rs = ps.executeQuery();
while(rs.next()) {
System.out.println(" id = " + rs.getInt("id"));
System.out.println(" name = " + rs.getString("name"));
System.out.println("password = " + rs.getString("password"));
System.out.println(" age = " + rs.getInt("age"));
System.out.println(" gender = " + rs.getString("gender"));
System.out.println(" email = " + rs.getString("email"));
System.out.println();
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
if(rs != null) {
try {
rs.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if(ps != null) {
try {
ps.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if(con != null) {
try {
con.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
}
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class ConnectionFactory {
private final static String JDBC_DRIVER_CLASS = "com.mysql.jdbc.Driver";
private final static String JDBC_URL = "jdbc:mysql://localhost:3306/test";
private final static String DATABASE_USERNAME = "root";
private final static String DATABASE_PASSWORD = "root";
private ConnectionFactory() {
}
public static Connection getConnection() throws SQLException {
Connection con = null;
try {
Class.forName(JDBC_DRIVER_CLASS);
con = DriverManager.getConnection(
JDBC_URL, DATABASE_USERNAME, DATABASE_PASSWORD
);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
return con;
}
"jdbc:mysql://localhost:3306/test";
当前这个test是???
--转自