在myeclipsw上怎么连接sql server,急~~~~

来源:百度知道 编辑:UC知道 时间:2024/05/17 21:07:18
打开了new database connection driver
Driver template,Driver name和Connection URL怎么填啊~~在就是Add JARs那要加入什么,谢谢
如果再能告诉我mysql和oracle怎么填的话,更加感激

给你写了一个完整的调用数据库的类你自己看吧!
还有就是记得导入JDBC包啊!要不然会报驱动异常!
package com;
import java.sql.*;

public class Aaa {
Connection con;
Statement st;
ResultSet rs;
public Connection getcon() throws Exception
{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
con=DriverManager.getConnection("jdbc:microsoft:Sqlserver://localhost:1433;databasename=pubs","sa","sa");
return con;
}

public Statement getst() throws Exception
{
st=getcon().createStatement();
return st;
}

public ResultSet getrs(String sql) throws Exception
{
rs=getst().executeQuery(sql);
return rs;
}

public int getr(String sql) throws Exception
{
int n=getst().executeUpdate(sql);
return n;
}

public void close() throws Exception
{
if(rs!=null)
{
rs.close();
}
if(st!=null)