前两天闲着没什么事,顺便拿着本JAVA的书看了看,觉得JAVA还是蛮有意思的,于是学了学.
下面是一些刚入门的小资料,特记下.
package bookstore;
import java.sql.*;
import java.util.Properties;
public class DBConnection {
//获取数据库连接类
public static Connection getConnection() throws SQLException {
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
}
catch (ClassNotFoundException ex)
{
ex.printStackTrace();
return null;
}
Properties sysProps = new Properties();
sysProps.put("user", "username"); //数据库的用户名
sysProps.put("password", "password"); //数据库的密码
return DriverManager.getConnection(
"jdbc:oracle:thin:@192.168.176.107:1521:sundun",sysProps);
}


//////////执行SQL语句//////////
private Connection con;
private Statement sqlStatemen;
public boolean executeSql(String sql) throws java.sql.SQLException
{
con = DBConnection.getConnection();
sqlStatemen= con.createStatement();
try
{
sqlStatemen.execute(sql);
}
catch(Exception e)
{
return false;
}
return true;

}
////////////////////////
}
下面是一些刚入门的小资料,特记下.