//在pom的依赖里增加 mysql的artifact,形如
//groupId = mysql
//artifactId = mysql-connector-java
//version = 5.1.25
package chen;
import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;
import org.omg.Messaging.SyncScopeHelper;
public class mystest {
static String url;
static String name;
static String password;
static{
Properties cfg=new Properties();
InputStream in=chen.mystest.class.getClassLoader().getResourceAsStream("db.properties");
try {
cfg.load(in);
System.out.println(cfg);
url=cfg.getProperty("url");
name=cfg.getProperty("name");
password=cfg.getProperty("password");
}
catch (Exception e) {
throw new RuntimeException(e);
}
}
public static void main(String[] args) throws IOException, ClassNotFoundException, SQLException {
Class.forName("com.mysql.jdbc.Driver");
System.out.println("chenggong");
Connection conn=DriverManager.getConnection(url,name,password);
System.out.println("链接成功");
Statement smt=conn.createStatement();
String sql="select * from test";
ResultSet rs= smt.executeQuery(sql);
while(rs.next()){
name=rs.getString("name");
String id=rs.getString("id");
int no=rs.getInt("no");
String name=rs.getString("name");
System.out.println(name);
System.out.println(no);
System.out.println(id);
}
}
}