JAVA问题??

来源:百度知道 编辑:UC知道 时间:2024/09/24 01:49:36
import java.io.*;
import java.sql.*;
import java.util.*;
class first{

public static Connection getConnection()throws SQLException,IOException{
Properties props=new Properties();
FileInputStream in=new FileInputStream("database.properties");
props.load(in);
in.close();

String drivers=props.getProperty("jdbc.drivers", drivers);
if(drivers!=null)
System.setProperty("jdbc.drivers", drivers);

String url=props.getProperty("jdbc.url");
String username=props.getProperty("jdbc.username");
String password=props.getProperty("jdbc.password");
return DriverManager.getConnection(url,username,password);

}

public static void main(String[] args){
try{
Connection con=null;
Statement state=con.createStatement();
state.execute("CREAT TABLE Greetings(

晕死。

Class.forName("这里写你数据库驱动类的名字");

各大数据库已经提供了相应的驱动和驱动名字。

database.properties 你的配置文件是这个,可能是你在这个配置文件中没有配置驱动.String url=props.getProperty("jdbc.url");
String username=props.getProperty("jdbc.username");
String password=props.getProperty("jdbc.password");
这个没有取到,配置一下就好了.

你们有导入jdbc的驱动吧,把那个驱动jar文件导入试试