急!java-mysql连接?
罗索客 发布于 2004-01-07 16:37 点击:次
|
|
调了好久,前几天也在论坛中请教过,不过还是没有解决问题!还请各位帮忙看看! 附的图片是调试出错的报告!user和password都是正确的! screen.width-333)this.width=screen.width-333\"> import java.sql.*; import java.io.*; import java.util.*; import java.lang.*; /*
TAG:
调了好久,前几天也在论坛中请教过,不过还是没有解决问题!还请各位帮忙看看! 附的图片是调试出错的报告!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(); } } }
(wqch) |
------分隔线----------------------------