作者在 2006-08-08 05:14:00 发布以下内容
import java.sql.*;
import java.io.*;
import java.util.*;
public class TestDb
{
public static void main(String args[])
{
try
{
Class.forName("com.mysql.jdbc.Driver");
System.out.println("load");
String url="jdbc:mysql://localhost:3306/myfirst";
String username="root";
String password="iloveyy";
Connection conn=DriverManager.getConnection(url,username,password);
System.out.println("content");
Statement stat=conn.createStatement();
stat.execute("DROP TABLE Greetings");
stat.execute("CREATE TABLE Greetings (Message 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));
stat.close();
conn.close();
}
catch(ClassNotFoundException ex)
{
ex.printStackTrace();
System.out.println("here");
}
catch(SQLException ex)
{
while(ex!=null)
{
ex.printStackTrace();
ex=ex.getNextException();
}
}
}
}
import java.io.*;
import java.util.*;
public class TestDb
{
public static void main(String args[])
{
try
{
Class.forName("com.mysql.jdbc.Driver");
System.out.println("load");
String url="jdbc:mysql://localhost:3306/myfirst";
String username="root";
String password="iloveyy";
Connection conn=DriverManager.getConnection(url,username,password);
System.out.println("content");
Statement stat=conn.createStatement();
stat.execute("DROP TABLE Greetings");
stat.execute("CREATE TABLE Greetings (Message 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));
stat.close();
conn.close();
}
catch(ClassNotFoundException ex)
{
ex.printStackTrace();
System.out.println("here");
}
catch(SQLException ex)
{
while(ex!=null)
{
ex.printStackTrace();
ex=ex.getNextException();
}
}
}
}