课程: Hands-On Introduction: Java

今天就学习课程吧!

今天就开通帐号,24,700 门业界名师课程任您挑!

Construct customer from data source

Construct customer from data source - Java教程

课程: Hands-On Introduction: Java

Construct customer from data source

- [Instructor] We have a database table that represents a customer and we also have a customer class that models this. What we need now is the construction of an object that represents a specific customer. Within the data source class, let's create a new method called get customer. So we'll say public static Customer get customer, and this method will accept the username of the customer. We'll need to craft a SQL query that will get the customer data from the database. We can do that using a string and Java. So we'll call this SQL, and then within quotes, we put the query. So let's say, select star from customers where username equals, and here we want to pass in the username variable that was passed into us. Technically, we could append it to the string. However, you should never send raw user input as part of a database query because it could be malicious input used as a SQL injection meant to steal data or manipulate your data…

内容