如何通过JAVA操作SQLserver数据库
1个回答
展开全部
之前远标教育老师教我们这样把sqlserver jdbc驱动加到classpath中,三个jar包。
import java.sql.*;
public class DbTest
{
Connection con;
Statement sta;
ResultSet rs;
String driver;
String url;
String user;
String pwd;
public DbTest()
{
driver = "sun.jdbc.odbc.JdbcOdbcDriver";
url = "jdbc:odbc:store_manager";
user = "share";
pwd = "share";
init();
}
public void init()
{
try{
rName(driver);
intln("driver is ok");
con = tConnection(url,user,pwd);
intln("conection is ok");
sta = eateStatement();
rs = sta.executeQuery("select * from room");
while( xt())
intln( tInt("roomNum"));
}
catch(Exception e)
{
intStackTrace();
}
}
public static void main(String[] args)
{
new DbTest();
}
}
import java.sql.*;
public class DbTest
{
Connection con;
Statement sta;
ResultSet rs;
String driver;
String url;
String user;
String pwd;
public DbTest()
{
driver = "sun.jdbc.odbc.JdbcOdbcDriver";
url = "jdbc:odbc:store_manager";
user = "share";
pwd = "share";
init();
}
public void init()
{
try{
rName(driver);
intln("driver is ok");
con = tConnection(url,user,pwd);
intln("conection is ok");
sta = eateStatement();
rs = sta.executeQuery("select * from room");
while( xt())
intln( tInt("roomNum"));
}
catch(Exception e)
{
intStackTrace();
}
}
public static void main(String[] args)
{
new DbTest();
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |