简体   繁体   English

使用JDBC插入Microsoft SQL

[英]Insert in Microsoft SQL using JDBC

I have some data coming from a machine in the following format: A (some value) B (some value) C (some value) and so on. 我有一些来自计算机的数据,格式如下:A(某些值)B(某些值)C(某些值),依此类推。

I have a database in the Microsoft SQL server 2008 with the columns named A, B, C and so on. 我在Microsoft SQL Server 2008中有一个数据库,其中的列名为A,B,C等。

I have downloaded the jdbc drivers for the MS SQL server 2008 and included in my classpath. 我已经下载了MS SQL Server 2008的jdbc驱动程序,并包含在我的类路径中。

I want to insert the values of A, B, C, etc in SQL when i receive it over from a different machine(port). 当我从其他计算机(端口)接收到A,B,C等值时,我想在SQL中插入它们。 Basically i have to design a server in Java which listens to that port for the values and when it receives the values, it inserts it into the MS SQL database. 基本上,我必须用Java设计一个服务器,该服务器侦听该端口的值,并在接收到值时将其插入MS SQL数据库。

Can someone help me code the above in Java? 有人可以帮我用Java编写以上代码吗? I am new to Java, hence finding it a bit difficult. 我刚接触Java,因此发现它有些困难。

Thank you. 谢谢。

Start with the JDBC tutorial: 从JDBC教程开始:

http://download.oracle.com/javase/tutorial/jdbc/ http://download.oracle.com/javase/tutorial/jdbc/

It should sort you out. 它应该把你整理出来。

Microsoft also has examples specific to SQL Server here: Microsoft在此处也有特定于SQL Server的示例:

http://support.microsoft.com/kb/313100 http://support.microsoft.com/kb/313100

That takes care of the database side. 那要照顾数据库方面。 When you say "server", I'll assume that you want a web based server that's listening on a port for HTTP requests. 当您说“服务器”时,我假设您需要一个基于Web的服务器,该服务器正在侦听HTTP请求的端口。 You'll need a servlet running in a servlet/JSP engine like Tomcat . 你需要一个的servlet在servlet / JSP引擎一样运行Tomcat的

Write an interface-based object that handles your database work; 编写一个处理数据库工作的基于接口的对象; thoroughly test it and put it aside. 彻底测试并将其放在一旁。 Then write a servlet that calls that object after validating and binding input values. 然后编写一个在验证和绑定输入值之后调用该对象的servlet。

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

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