简体   繁体   English

Java> Eclipse和SQL Server

[英]Java> Eclipse and SQL Server

Im pretty new with Java (though im experienced with C#) Anyway I've Googled in the last few hours and i can't understand something, hoping you can help me with some guideness. 我是Java的新手(虽然我对C#经验丰富)无论如何,我在过去的几个小时里用Google搜索,我无法理解某些东西,希望你能帮助我一些指导。

I'd like to use Eclipse with SQL Server and i have no idea how am i doing that Iv'e seen some plugin called SQLExplorer but i just can't figure what are the steps to integrate with that. 我想将Eclipse与SQL Server一起使用,我不知道我是怎么做的,我看过一些名为SQLExplorer的插件,但我无法确定与之集成的步骤是什么。

Regarding: 关于:

  • what is the best way of doing that? 这样做的最佳方式是什么?
  • any guide? 任何指南? full tutorial? 完整教程?
  • maybe u have some source code example of a connection by SQL? 也许你有一些SQL连接的源代码示例?
  • should i use that plugin? 我应该使用该插件吗? how? 怎么样?
  • why is it so difficult to find info bout this issue? 为什么这个问题很难找到信息呢? isn't eclipse familiar with SQL? 是不是eclipse熟悉SQL?

Thank you all. 谢谢你们。

Java and databases go together like bread and butter, but the language is just different enough that you might have issues breaking in. There are a number of different levels at which things can be integrated: the traditional query/result API is called JDBC, and all you need to work with any database from Java code is the appropriate JDBC driver. Java和数据库就像面包和黄油一样,但语言不同,你可能会遇到问题。有很多不同的层次可以集成东西:传统的查询/结果API称为JDBC,从Java代码中使用任何数据库所需的只是适当的JDBC驱动程序。 Here is the official one from Microsoft for SQL Server, and here is a tutorial about using the JDBC API. 是Microsoft针对SQL Server的官方版本, 是一个关于使用JDBC API的教程。

Above that, there are object-relational mapping tools like Hibernate which let you persist Java objects directly onto your database. 除此之外,还有像Hibernate这样的对象关系映射工具,它允许您将Java对象直接保存到数据库中。 Hibernate automates a lot of the mapping and lets you work at a high level. Hibernate自动化了很多映射,让您可以在高级别工作。 Hibernate is an enormous subject; Hibernate是一个巨大的主题; start here. 这里开始

What SQLExplorer, and tools like it, let you do is browse around in a database, exploring the tables and the data in them. 您可以使用SQLExplorer和类似工具浏览数据库,浏览表格及其中的数据。 It's not something you use with code, but rather interactively to examine the data you're working with. 这不是您使用代码的东西,而是交互式地检查您正在使用的数据。

Here is a JDBC "Hello World," assuming the default database on the local machine, a table named some_table_name has a character-valued column in the first position: 这是一个JDBC“Hello World”,假设本地机器上有默认数据库,名为some_table_name的表在第一个位置有一个字符值列:

Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
String connectionUrl = "jdbc:sqlserver://localhost";
Connection con = DriverManager.getConnection(connectionUrl);
Statement s = con.createStatement();
ResultSet r = s.executeQuery("SELECT * FROM some_table_name");
while (r.next()) {
    System.out.println(r.getString(1));
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM