import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
// Notice, do not import com.mysql.jdbc.*
// or you will have problems!
public class HelloWorld {
public static void main(String[] args) {
Connection conn = null;
try {
// The newInstance() call is a work around for some
// broken Java implementations
Class.forName("com.mysql.jdbc.Driver").newInstance();
} catch (Exception ex) {
// handle the error
}
try {
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","mypassword");
// Do something with the Connection
} catch (SQLException ex) {
// handle any errors
System.out.println("SQLException: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("VendorError: " + ex.getErrorCode());
}
}
}
ubuntuからmysqlに接続しようとしています。私はJAVAの基本的な考えさえ持っていません。このコードは mysql サイトからコピーされました。誰でもmysqlを簡単なプログラムに接続するのを手伝ってくれますか?