在java中怎样与SQL2000做连接?? 老师给我们留了SQL2000的课程设计~~我想用JAVA与之结合可是在学习时我在学习java与SQL2000时不知道这样与之连接~~~请大家给一点点意见~~~和学习的经验之谈~~ 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 将安装驱动后产生的三个文件msbase.jar;mssqlserver.jar;msutil.jar放到C:\j2sdk1.4.2_05\jre\lib\ext目录下就可以编程了,不需要另外配置环境变量了!然后试着运行下面的代码! import java.sql.*; import java.io.*; import java.util.*; /** 6. This program tests that the database and the JDBC 7. driver are correctly configured. */ class TestDB { public static void main (String args[]) { try { runTest(); } catch (SQLException ex) { while (ex != null) { ex.printStackTrace(); ex = ex.getNextException(); } } catch (IOException ex) { ex.printStackTrace(); } } /**32. Runs a test by creating a table, adding a value, showing the table contents, and33. removing the table.34. */ public static void runTest() throws SQLException, IOException { Connection conn = getConnection(); try { Statement stat = conn.createStatement(); ResultSet result = stat.executeQuery("SELECT * FROM Mst_Company"); while(result.next()) { System.out.println(result.getString(1)); } } finally { conn.close(); } } /** Gets a connection from the properties specified in the file database.properties @return the database connection */ public static Connection getConnection() throws SQLException, IOException {try{Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance(); }catch(Exception e){System.out.println(e);} String url ="jdbc:microsoft:sqlserver://192.168.1.24:1433;DatabaseName=marunaka"; String username = "dbuser"; String password = "qaz123"; return DriverManager.getConnection(url, username, password); } }修改一下,ip地址,数据库名,用户名,密码,sql语句,你就可以运行了! 描述JAVA中异常处理的机制 日期问题-给定年月,得到每一天都是星期几??? AWT透明图片问题 String 对象的问题,请指点! Java5的泛型使用问题 JAVA技术交流群(10721223)欢迎加入共同进步 a = null 和 a.length() = 0 有什么区别? JAVA如何进行数据库连接(sql2000) 日期处理问题,求大神帮助! 如何将.class变成.exe文件 论文求助 在java中怎么样获取鼠标左键!如何将物体旋转后的效果在相同位置显示出来?(图形是三维)
放到C:\j2sdk1.4.2_05\jre\lib\ext目录下就可以编程了,不需要另外配置环境变量了!然后试着运行下面的代码!
import java.sql.*;
import java.io.*;
import java.util.*;
/**
6. This program tests that the database and the JDBC
7. driver are correctly configured.
*/
class TestDB
{
public static void main (String args[])
{
try
{
runTest();
}
catch (SQLException ex)
{
while (ex != null)
{
ex.printStackTrace();
ex = ex.getNextException();
}
}
catch (IOException ex)
{
ex.printStackTrace();
}
} /**
32. Runs a test by creating a table, adding a value, showing the table contents, and
33. removing the table.
34. */
public static void runTest()
throws SQLException, IOException
{
Connection conn = getConnection();
try
{
Statement stat = conn.createStatement(); ResultSet result = stat.executeQuery("SELECT * FROM Mst_Company");
while(result.next())
{
System.out.println(result.getString(1));
}
}
finally
{
conn.close();
}
} /**
Gets a connection from the properties specified
in the file database.properties
@return the database connection
*/
public static Connection getConnection()
throws SQLException, IOException
{
try
{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
}
catch(Exception e)
{
System.out.println(e);
} String url ="jdbc:microsoft:sqlserver://192.168.1.24:1433;DatabaseName=marunaka";
String username = "dbuser";
String password = "qaz123"; return DriverManager.getConnection(url, username, password);
}
}修改一下,ip地址,数据库名,用户名,密码,sql语句,你就可以运行了!